Two more R/S differences

Martin Maechler Martin Maechler <>
Wed, 7 Jan 1998 09:29:02 +0100

(Another discussion out of R-core,  
 I think  anyone in R-devel might have an opinion -- MM):

>>>>> "KH" == Kurt Hornik <> writes:

>>>>> Martin Maechler writes:
>>>>> "KH" == Kurt Hornik <> writes:
    KH> * Bug or feature?
    R> NULL + NULL
    R> NULL > NULL
    Error: comparison is possible only for vector types
    R> NULL & NULL
    Error in NULL & NULL : operations are possible only for numeric or
    logical types

    KH> whereas S-PLUS:

    >>>> NULL > NULL
    >>>> NULL + NULL
    >>>> NULL & NULL

    >> NULL + NULL real(0) and NULL are not so different..  I think R is
    >> better here...

    >> The other two: R (once more) is stricter in order to help avoiding
    >> buggy code.

    >> In R,
    >>> real(0) > integer(0)
    >> logical(0)

    >> Therefore, I don't see why NULL > NULL should work...

    >> In sum, I think R behaves as we want, and the different behavior
    >> should go into the FAQ and probably also be mentioned in some *.Rd
    >> files.

    KH> Again, I am not entirely convinced yet.

you are right, me neither anymore..

We should discuss this some more

    KH> Why does adding two empty objects give something non-NULL?  To me,
    KH> this seems to violate `nihil nihilo fit' (the ``no-arbitrage
    KH> condition'').

I think the paradigm is

 NULL    :=  list of length 0  + is sometimes coerced to vector of length 0
 real(0) :=  numeric(0) =  numeric vector of length 0

The real point of discussion is:

##   In which situations should
##   NULL silently be coerced to numeric(0) / logical(0) / character(0) ?

Currently,  S does this silent coercion very often
while  R does not.
I start thinking that maybe R should change here.

    KH> Also, why is it o.k. to ADD two empty objects, but not to compare
    KH> them?  (Shouldn't two NULL objects be the same?)

    KH> Btw, the code in chron that got me started on this was

    KH> 	if(any(o1 != o2))

    KH> trying to figure out whether two origins (o1, o2) were different.
    KH> Under R, this code fails if at least one of the origins is NULL.
    KH> What is the right way of coding this?  (Surely not the

    KH> 	if(any(o1 - o2))

    KH> I changed it to :-))

All was ok, if both  o1 and o2  where never NULL but rather numeric(0),
however see above.

-- Martin
r-devel mailing list -- Read
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: