[Rd] possible bug: NULL equality in lists.

Seth Falcon sfalcon at fhcrc.org
Tue Mar 7 16:37:12 CET 2006


Uwe Ligges <ligges at statistik.uni-dortmund.de> writes:

> Charles Dupont wrote:
>
>> I was messing around with R and I found an example R behaving oddly:
>> 
>> a <- alist(NULL, "bob", c(3,6,2,3))
>> a
>> a == 'NULL'
>> a == "NULL"
>> a == 'cat'
>> 
>
>
> Always use is.null() to test on NULL, as in:

What should I do if I want to check for the string "NULL"?

> a <- list(NULL, "NULL", NA, "NA")

> a == "NULL"
[1]  TRUE  TRUE FALSE FALSE

> a == "NA"
[1] FALSE FALSE  TRUE  TRUE

These are because of as.character:

> as.character(a)
[1] "NULL" "NULL" "NA"   "NA"  

Yet,

> as.character(NULL)
character(0)
> as.character(NA)
[1] NA



+ seth



More information about the R-devel mailing list