[Rd] '==' operator: inconsistency in data.frame(...) == NULL
Hilmar Berger
berger @end|ng |rom mp||b-ber||n@mpg@de
Wed Sep 11 11:55:10 CEST 2019
Dear Martin,
On 11/09/2019 09:56, Martin Maechler wrote:
>
> > I wonder if data.frame(<some non-empty data>) == NULL should also return
> > a value instead of an error. R help reads:
>
> > "At least one of |x| and |y| must be an atomic vector, but
> > if the other is a list R attempts to coerce it to the
> > type of the atomic vector: this will succeed if the list
> > is made up of elements of length one that can be coerced
> > to the correct type.
>
> > If the two arguments are atomic vectors of different
> > types, one is coerced to the type of the other, the
> > (decreasing) order of precedence being character, complex,
> > numeric, integer, logical and raw."
>
> > It is not clear from the help what to expect for NULL or
> > empty atomic vectors.
>
> Well, strictly speaking an error would be expected for NULL,
> as it is *not* an atomic vector, and your main issue
>
> " data.frame(..) == NULL "
>
> would already be settled by the first half sentence from the
> doc, and strictly speaking, even data.frame(NULL) == NULL
> "should" return an error ((Note: I'm not saying it really
> should, but at least the reference does not say it should work at all))
Thanks, this explanation makes total sense to me. I did not consider
that NULL might be non-atomic. Strangely, is.atomic(NULL) returns TRUE.
On the other hand, I understand that one would not like to treat it like
atomic in ==.
However, in this case one might expect that the error message would be
more like that for S4 objects (which always seem to report an
informative error message for ==):
> Pos <- setClass("Pos", slots = c(latitude = "numeric", longitude =
"numeric", altitude = "numeric"))
> p = Pos()
> p == NULL
Error in p == NULL :
comparison (1) is possible only for atomic and list types
> p == "FOO"
Error in p == "FOO" :
comparison (1) is possible only for atomic and list types
In the data.frame()==NULL cases I have the impression that the fact that
both sides are non-atomic is not properly detected and therefore R tries
to go on with the == method for data.frames.
From a cursory check in Ops.data.frame() and some debugging I have the
impression that the case of the second argument being non-atomic or
empty is not handled at all and the function progresses until the end,
where it fails in the last step on an empty value:
matrix(unlist(value, recursive = FALSE, use.names = FALSE),
nrow = nr, dimnames = list(rn, cn))
Best regards,
Hilmar
--
Dr. Hilmar Berger, MD
Max Planck Institute for Infection Biology
Charitéplatz 1
D-10117 Berlin
GERMANY
Phone: + 49 30 28460 430
Fax: + 49 30 28460 401
E-Mail: berger using mpiib-berlin.mpg.de
Web : www.mpiib-berlin.mpg.de
[[alternative HTML version deleted]]
More information about the R-devel
mailing list