From h.wickham at gmail.com  Wed Oct 29 21:46:43 2014
From: h.wickham at gmail.com (Hadley Wickham)
Date: Wed, 29 Oct 2014 15:46:43 -0500
Subject: [Rd] Unexpected behavior of identical() with language objects
In-Reply-To: <CAPPM_gQJFLHPs__OwVyNuftkWz2X7+sn_LwRzfpgrT6qdg37nw@mail.gmail.com>
References: <CAFOpNVGxxqH0uYjouj6rG9b9LdbigQQbNDWgvS8NxhYnn61F8A@mail.gmail.com>
	<CAPPM_gQJFLHPs__OwVyNuftkWz2X7+sn_LwRzfpgrT6qdg37nw@mail.gmail.com>
Message-ID: <CABdHhvGtKp4-J6G--aJ1+Y-rNbugOtW0kzjuevvm_EdQTANnJw@mail.gmail.com>

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



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