[Rd] possible bug: NULL equality in lists.

Uwe Ligges ligges at statistik.uni-dortmund.de
Tue Mar 7 16:13:02 CET 2006


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:

   sapply(a, is.null)

Uwe Ligges



> If I create a list with a NULL value
>   >a <- alist(NULL, "bob", c(3,6,2,3))
>   >a
> [[1]]
> NULL
> 
> [[2]]
> [1] "bob"
> 
> [[3]]
> c(3, 6, 2, 3)
> 
> and run some tests on 'a', the '== "NULL' test returns TRUE for the NULL 
> entry in the list 'a'.
>   >a == 'NULL'
> [1]  TRUE FALSE FALSE
>   >a == "NULL"
> [1]  TRUE FALSE FALSE
>   >a == 'cat'
> [1]  FALSE FALSE FALSE
> 
> This is consistent for every example of NULL's in a list that I can 
> think of.
> 
> Is this a bug or undocumented correct behavior?
> 
> Here is my version output
> 
> platform i486-pc-linux-gnu
> arch     i486
> os       linux-gnu
> system   i486, linux-gnu
> status
> major    2
> minor    2.0
> year     2005
> month    10
> day      06
> svn rev  35749
> language R
> 
> 
> Thanks
> 
> Charles



More information about the R-devel mailing list