[Rd] all.equal, classes, and order of arguments
Martin Maechler
maechler at stat.math.ethz.ch
Thu May 8 11:16:17 CEST 2008
>>>>> "hw" == hadley wickham <h.wickham at gmail.com>
>>>>> on Thu, 1 May 2008 20:53:10 -0500 writes:
>> a <- list()
>> b <- structure(list(), class=c("list", "a"))
>> all.equal(a, b)
hw> [1] "Attributes: < target is NULL, current is list >"
>> all.equal(b, a)
hw> [1] "Attributes: < Modes: list, NULL >"
hw> [2] "Attributes: < names for target but not for current >"
hw> [3] "Attributes: < Length mismatch: comparison on first 0 components >"
hw> which does not reveal the simple difference between a and b. I had
hw> also expected that all.equal would (in some sense) be symmetric with
hw> respect to its arguments, but I can see that this would be very hard
hw> to guarantee in general.
hw> Hadley
You can use 'check.attributes' :
> str(all.equal)
function (target, current, ...)
> str(all.equal.list)
function (target, current, check.attributes = TRUE, ...)
> a <- list(); b <- structure(a, class=c("list", "a")); all.equal(a, b)
[1] "Attributes: < target is NULL, current is list >"
> all.equal(a,b, check.attributes=FALSE)
[1] TRUE
> all.equal(b,a, check.attributes=FALSE)
[1] TRUE
>
Martin Maechler, ETH Zurich
More information about the R-devel
mailing list