From charles.dupont at vanderbilt.edu  Tue Mar  7 18:08:03 2006
From: charles.dupont at vanderbilt.edu (Charles Dupont)
Date: Tue, 07 Mar 2006 11:08:03 -0600
Subject: [Rd] possible bug: NULL equality in lists.
In-Reply-To: <440DABCA.6030108@statistik.uni-dortmund.de>
References: <440D9B1E.6020001@vanderbilt.edu>	<440DA2FE.8050709@statistik.uni-dortmund.de>	<m2wtf6w9jr.fsf@ziti.local>
	<440DABCA.6030108@statistik.uni-dortmund.de>
Message-ID: <440DBDF3.1010608@vanderbilt.edu>

Uwe Ligges wrote:
> Seth Falcon wrote:
> 
> 
>>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"?
> 
> 
> These are all dangerous, hence use the "safe" ways:
> 
> sapply(a, is.null)
> sapply(a, identical, "NULL")
> sapply(a, is.na)
> sapply(a, identical, "NA")
> 
> Best,
> Uwe

For the NA list problem.  It would be better if 'as.character' when
converting a list when it finds a NA value to set that element to the
string NA value not "NA" the string.


Charles

> 
> 
>>>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
>>
>>______________________________________________
>>R-devel at r-project.org mailing list
>>https://stat.ethz.ch/mailman/listinfo/r-devel
> 
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
> 


-- 
Charles Dupont	Computer System Analyst		School of Medicine
		Department of Biostatistics	Vanderbilt University



[Rd] possible bug: NULL equality in lists.
Charles Dupont