Re: [Rd] all.equal, classes, and order of arguments

From: Martin Maechler <maechler_at_stat.math.ethz.ch>
Date: Thu, 08 May 2008 11:16:17 +0200

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



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Thu 08 May 2008 - 09:20:08 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 08 May 2008 - 09:31:27 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive