[R] identical calls are not equal !?

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Wed Jun 12 17:02:51 CEST 2002


oehl_list at gmx.de writes:

> Can please someone familiar with the R internals enlighten me on the
> following strange observation:
> 
> # this is IDENTICAL as expected
> identical(substitute(substitute()), substitute(substitute()))
> # but NOT EQUAL !????
> substitute(substitute()) == substitute(substitute())
> 
> # I originally found it on 
> t2 <- function(e){
>         substitute(e)
> }
> t2(substitute(x==y, list(y=y)))[1]
> # I would expect all of the following to be equal !?
> t2(substitute(x==y, list(y=y)))[1] == substitute(substitute())
> t2(substitute(x==y, list(y=y)))[1] == substitute(substitute())[1]
> identical(t2(substitute(x==y, list(y=y)))[1], substitute(substitute())[1])
> identical(t2(substitute(x==y, list(y=y)))[1], substitute(substitute()))
> identical(t2(substitute(x==y, list(y=y)))[1], quote(substitute()))
> 
> I have a guess that .Primitive("==") on method dispatch somehow treats its
> first argument different from its second. However, if so, is this intended? Or
> is it an unavoidable implementation issue? Or a bug?

Shorter version:

b <- quote(f())
a <- b
a==b

It's a bug. The intention of the code in do_relop_dflt is that calls are
equal if they deparse to the same string. 

However, this is plain wrong:

67              SET_STRING_ELT(tmp, 0, (iS) ? PRINTNAME(x) : deparse1(x, 0));
68              REPROTECT(x = tmp, xpi);

since deparse1(x, 0) is a SEXP and not a string.

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help 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-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list