Skip to content
Prev 12438 / 63461 Next

Unexpected behaviour of identical (PR#6799)

Tony Plate wrote:
We're certainly down in the fine points here, so arguments either way
aren't very strong, but on the whole it seems cleaner to keep identical
on the pedantic side, dealing with what's actually in the object, rather
than what was "meant".

Yes, for practical purposes attribute order better NOT matter, but we do
store the attributes in a way that creates an "order", i.e., as an
internal vector or list structure rather than, say, a hash table.
Treating attributes as a set would have some logical appeal, but it
seems likely the fix would have to be more widespread than just to
identical().  Otherwise, for example, you could find yourself in a
situation where:
  identical(x,y)
was TRUE but
  identical(attributes(x), attributes(y))
was FALSE, because attributes() just reported out the attributes in
their (irrelevant) stored order.
Yes, as above, it does seem that a satisfactory solution would require
treating attributes() as something other than a vector, returned in
internal order.

Once started down this path, there are a number of other cases where a
vector has been used, for convenience, when an unordered set was the
more likely model.  I think there have been debates over whether the
order of the levels of an unordered factor should be considered
relevant.

It would increase consistency to replace vectors in these examples with
an efficient structure that only depended on the set of values
(presumably a suitable hashing mechanism would do).  But it's not too
likely to get to the head of the priority queue, I'd guess.

It's not out of the question, as an alternative that doesn't require
deep changes to the system, to write methods for identical() for some
classes of objects.