[Rd] all.equal() for mismatching names {was "Enlightenment sought..."}

Martin Maechler maechler at stat.math.ethz.ch
Fri Dec 2 14:44:22 CET 2005


>>>>> "BeT" == Berwin A Turlach <berwin at maths.uwa.edu.au>
>>>>>     on Fri, 2 Dec 2005 18:31:13 +0800 writes:

    BeT> First, I recently had reasons to read the help page of as.vector() and
    BeT> noticed in the example section the following example:

    BeT> x <- c(a = 1, b = 2)
    BeT> is.vector(x)
    BeT> as.vector(x)
    BeT> all.equal(x, as.vector(x)) ## FALSE

actually 'FALSE' was never the case,  but "non-TRUE" once was, see below.

    BeT> However, in all versions of R in which I executed this example, the
    BeT> all.equal command returned TRUE which suggest that either the comment
    BeT> in the help file is wrong or the all.equal/as.vector combination does
    BeT> not work as intended in this case.  For the former case, I attach
    BeT> below a patch which would fix vector.Rd.

We recently had the following posting on R-devel
https://stat.ethz.ch/pipermail/r-devel/2005-October/034962.html
(Subject: [Rd] all.equal() improvements (PR#8191))
where Andrew Piskorsky proposed a (quite
extensive) patch to all.equal()  in order to  make sure that
things like names must match for all.equal() to return TRUE.


I did agree back then, and Brian partly disagreed with the very
valid argument that all.equal() has been used in code testing
(particularly R CMD check for packges), and that changes to make all.equal()
more "picky" might well have bad consequences for package
testing.  Also Andy didn't provide the necessary patches to the
documentation that would have been entailed.  
Well, all that's just an excuse for the fact that I had really
lost the topic out of sight ;-)

However, I'd like to take up the case, and I believe we should
fix all.equal() for at at least the following reasons:

1- logical consistency

2- earlier R versions were more picky about name mismatch
   (upto R version 1.6.2) :

  > x <- c(a=1, b=pi); all.equal(x, as.vector(x))
  [1] "names for target but not for current"
  [2] "TRUE"

3- two versions of S-plus were more picky too,
   in particular, S+3.4 which used to be our prototype:
 
   > x <- c(a=1, b=pi); all.equal(x, as.vector(x))
   [1] "names for target but not for current"
   attr(, "continue"):
   [1] T

   Here's Splus 6.2 :

   > x <- c(a=1, b=pi); all.equal(x, as.vector(x))
   [1] "target, current classes differ: named : numeric"
   [2] "class of target is \"named\", class of current is \"numeric\" (coercing target to class of current)"

----

I really don't expect package checkings to fail because of a
change.
If some would start failing, a fix should be quiet simple for
the package author and would help find inconsistencies in their
own code IMO.

Martin Maechler, ETH Zurich



More information about the R-devel mailing list