From ligges at statistik.uni-dortmund.de  Tue Mar  7 18:12:55 2006
From: ligges at statistik.uni-dortmund.de (Uwe Ligges)
Date: Tue, 07 Mar 2006 18:12:55 +0100
Subject: [Rd] possible bug: NULL equality in lists.
In-Reply-To: <m2slpuw5vj.fsf@ziti.local>
References: <440D9B1E.6020001@vanderbilt.edu>	<440DA2FE.8050709@statistik.uni-dortmund.de>	<m2wtf6w9jr.fsf@ziti.local>	<440DABCA.6030108@statistik.uni-dortmund.de>
	<m2slpuw5vj.fsf@ziti.local>
Message-ID: <440DBF17.9080400@statistik.uni-dortmund.de>

Seth Falcon wrote:

> Uwe Ligges <ligges at statistik.uni-dortmund.de> writes:
> 
>>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")
> 
> 
> Point taken, but is the behavior of as.character correct?
> 
> as.character(list(NULL))
> 
> as.character(NULL)


I thought about it quite a while. I think the current bahaviour is quite 
OK. What should as.character do in the follwing case:
   as.character(list("A", NA, NULL))
?

Note that it only can return a character vector...!

So, should it return a character vector of length 2? That's a bad idea, 
if the length is reduced.

Moreover, as.character() does not get a NA or a NULL object for coercion 
but an element of type list that itself conatins NA or NULL...

So if you want to convert a list to character and *keep* NA/NULL values, 
you can only say:

  lapply(a, as.character)

Uwe






> + seth
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



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