Skip to content
Prev 180880 / 398525 Next

exists function on list objects gives always a FALSE

Linlin Yan wrote:
is.null is unhelpful here, in that lists can contain NULL as a named
element, and retrieving a non-existent element returns NULL:

    foo = list(bar=NULL)
    is.null(foo$bar)
    # TRUE
    is.null(foo$foo)
    # TRUE

i must admit i find it surprising that ?'$' does not appropriately
explain what happens if a list is indexed with a name not included in
the list's names.  the closest is

" When extracting, a numerical, logical or character 'NA' index
     picks an unknown element and so returns 'NA' in the corresponding
     element of a logical, integer, numeric, complex or character
     result, and 'NULL' for a list. "

but it's valid for NAs in the index, and

"  If no match is found then 'NULL' is returned. "

but it's in the section on environments.


vQ