[Rd] Unexpected behavior of identical() with language objects

Hadley Wickham h.wickham at gmail.com
Wed Oct 29 21:46:43 CET 2014


>> Is this expected behavior? I can't seem to find anything in the help
>> for identical that relates to this.
>>
> It's not in ?identical, but ?Paren gives you some pointers.
> str(quote((a))) and str(quote({a})) are also informative.

Yes, looks like srcrefs are to blame:

x <- quote({ a })
y <- quote({ a })

identical(x, y)
# [1] FALSE

attr(x, "srcref") <- NULL
attr(x, "srcfile") <- NULL
attr(x, "wholeSrcref") <- NULL

attr(y, "srcref") <- NULL
attr(y, "srcfile") <- NULL
attr(y, "wholeSrcref") <- NULL
identical(x, y)
# [1] TRUE

Maybe identical() needs an ignore.srcref option? Normally when
comparing expressions or functions, you want to compare the code, not
it's textual representation.

Hadley

-- 
http://had.co.nz/



More information about the R-devel mailing list