Skip to content
Prev 12432 / 63461 Next

Unexpected behaviour of identical (PR#6799)

AFAIK identical() first introduced by Chambers in "Programming with 
data"?  On p262 he writes:

identical: The two objects must be exactly equal in all respects; if not 
identical returns FALSE
all.equal: The two objects are expected to be identical up to small 
differences that might be considered irrelevant...

Taken literally, this would seem to argue against identical() treating 
attributes as a set (unless one were to tighten up the definition of 
attributes in Section 2.2 of the R Language Definition to explicitly state 
that attributes are to be treated as an unordered set).

However, given the primary use of identical() on complex objects is in 
software testing, and AFAIK no software depends on the order of attributes, 
I still think it would be reasonable for attributes to be treated as a set 
by identical().  (Unless anyone can show that it's important to recognize 
order of attributes in some code.)

I'm proposing a more general fix for this problem because I strongly 
suspect that factor subsetting is not the only thing that can change the 
order of attributes, and because I've wasted many hours tracking down 
problems that turned out to be caused by problems with data.dump() and 
identical() in S-plus.  Another possible fix might be for the attr() and 
attributes() replacement functions to store attributes as a sorted list.  I 
don't know if this would be easy or difficult to implement, or what 
consequences it might have in terms of existing tests that involve printed 
output of attributes.

-- Tony Plate
At Tuesday 09:13 AM 4/20/2004, Prof Brian Ripley wrote: