Skip to content

R-alpha: ==NULL

2 messages · Martin Maechler, Thomas Lumley

#
Tom> Any comparison with NULL generates an error Error: comparison is
    Tom> possible only for vector types whereas in S(-PLUS) it gives NA,
    Tom> which seems more sensible.

    Tom> Along similar lines, comparison with a length 0 vector returns
    Tom> logical(0) in R but NA in S.

Is n't  logical(0)  more  logical than  NA ?

I agree that it would be best  (convenience)
if   'NULL==1' returned the same as 'numeric(0)==1'.

At the moment, I don't see why compatibility with S  should be important
here:
		if( NULL == anything)  
or, e.g.,	if( numeric(0) == numeric(0) )

give an error anyway, i.e., you have to test for length 0 _anyway_
in the cases where one comparison argument may have zero length.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
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
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#
On Thu, 1 May 1997, Martin Maechler wrote:

            
^^^^^ Aaargh! Not "Tom", please.
I didn't (previously) make any comment on this -- I only said that NA was
more logical than an error message.  However, the advantage of returning
NA is that NA | TRUE is TRUE, NA & FALSE is FALSE, which doesn't happen
with logical(0). Also, from a compatibility point of view one of them is
tested with is.na(), the other with length(), so it can matter which one
you use.  Of course no-one should deliberately write code where it
matters, but these things happen. 

It seems in fact that logical(0) | TRUE causes R to freeze (R0.49,
sparc solaris).


Thomas Lumley
------------------------------------------------------+-----
Biostatistics		: "Never attribute to malice what  :
Uni of Washington	:  can be adequately explained by  :
Box 357232		:  incompetence" - Hanlon's Razor  :
Seattle WA 98195-7232	:				   :
------------------------------------------------------------

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
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
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-