From maechler at stat.math.ethz.ch  Thu May  8 11:16:17 2008
From: maechler at stat.math.ethz.ch (Martin Maechler)
Date: Thu, 8 May 2008 11:16:17 +0200
Subject: [Rd] all.equal, classes, and order of arguments
In-Reply-To: <f8e6ff050805011853g66127107xb0bcae541f19b67@mail.gmail.com>
References: <f8e6ff050805011853g66127107xb0bcae541f19b67@mail.gmail.com>
Message-ID: <18466.50401.712820.150352@stat.math.ethz.ch>

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



[Rd] all.equal, classes, and order of arguments
Martin Maechler