[Rd] is.null(list()) is FALSE ?
Martin Maechler
Martin Maechler <maechler@stat.math.ethz.ch>
Tue, 21 Mar 2000 17:57:55 +0100 (MET)
>>>>> "TL" == Thomas Lumley <thomas@biostat.washington.edu> writes:
TL> On Tue, 21 Mar 2000, Torsten Hothorn wrote:
>>
>> On R-1.0.0, debian GNU/Linux,
>>
R> is.null(list())
>> FALSE
>>
>> conflicts with the help for ?is.null:
>>
>> Examples:
>>
>> is.null(list()) # TRUE (not so in S)
>> is.null(integer(0))# F
>> is.null(logical(0))# F
>> as.null(list(a=1,b='c'))
>>
>> and, I would like is.null(list()) to be TRUE :-)
TL> My guess is that this dates from old-style pairlists, where list() could
TL> easily be NULL.
well guessed!
TL> Now a list is internally a vector, so list() is a vector
TL> of length zero and so is stored as a VECTOR node.
and we had decision quite a while ago that is.null(list()) should give
FALSE {and this is S compatible}.
I've already committed fix for the wrong comment above :
cvs diff -r 1.3 src/library/base/man/NULL.Rd
...
diff -r1.3 -r1.3.22.1
24c24
< is.null(list()) # TRUE (not so in S)
---
> is.null(list()) # FALSE (on purpose!)
TL> Also, a difficulty with storing list() as NULL is that you can't set
TL> attributes on NULL:
R> a<-NULL
R> attr(a,"foo")<-"bar"
TL> Error: attempt to set an attribute on NULL
R> a<-list()
R> attr(a,"foo")<-"bar"
R> a
TL> list()
TL> attr(,"foo")
TL> [1] "bar"
TL> -thomas
TL> Thomas Lumley
TL> Assistant Professor, Biostatistics
TL> University of Washington, Seattle
Martin Maechler <maechler@stat.math.ethz.ch> http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum LEO D10 Leonhardstr. 27
ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND
phone: x-41-1-632-3408 fax: ...-1228 <><
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._