[Rd] '==' operator: inconsistency in data.frame(...) == NULL

Hilmar Berger berger @end|ng |rom mp||b-ber||n@mpg@de
Wed Sep 11 12:24:35 CEST 2019


Another example where a data.frame is compared to (here non-null, 
non-empty) non-atomic values in Ops.data.frame, resulting in an error 
message:

setClass("FOOCLASS2",
          slots = c(M="matrix")
)
ma = new("FOOCLASS2", M=matrix(rnorm(300), 30,10))

 > isS4(ma)
[1] TRUE
 > ma == data.frame(a=1:3)
Error in eval(f) : dims [product 1] do not match the length of object [3]

As for the NULL/logical(0) cases I would suggest to explicitly test for 
invalid conditions in Ops.data.frame and generate a comprehensible 
message (e.g. "comparison is possible only for atomic and list types") 
if appropriate.

Best regards,
Hilmar


On 11/09/2019 11:55, Hilmar Berger wrote:
>
> 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)) 

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



More information about the R-devel mailing list