Skip to content

identical calls are not equal !?

3 messages · Jens Oehlschlägel, Peter Dalgaard

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

Best


Jens Oehlschl?gel
#
oehl_list at gmx.de writes:
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.
#
Peter Dalgaard BSA <p.dalgaard at biostat.ku.dk> writes:
Not quite. It's supposed to be a SEXP, but a CHARSXP and not a STRSXP.
The fix is simple enough to be committed for 1.5.1, I think.