From ligges at statistik.uni-dortmund.de  Tue Mar  7 16:13:02 2006
From: ligges at statistik.uni-dortmund.de (Uwe Ligges)
Date: Tue, 07 Mar 2006 16:13:02 +0100
Subject: [Rd] possible bug: NULL equality in lists.
In-Reply-To: <440D9B1E.6020001@vanderbilt.edu>
References: <440D9B1E.6020001@vanderbilt.edu>
Message-ID: <440DA2FE.8050709@statistik.uni-dortmund.de>

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



[Rd] possible bug: NULL equality in lists.
Uwe Ligges