[Rd] t() dropping NULL dimnames {was "all.equal() for mismatching names..."}

Andrew Piskorski atp at piskorski.com
Fri Dec 2 18:43:01 CET 2005


On Fri, Dec 02, 2005 at 05:56:31PM +0100, Martin Maechler wrote:

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

>     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

My PR#8191 patch to all.equal() does fix that, e.g.:

  > x <- c(a = 1, b = 2) 
  > is.vector(x) 
  [1] TRUE 
  > all.equal(x, as.vector(x)) 
  [1] "names"                          "for Target but not for Current" 
  > x 
  a b  
  1 2  
  > as.vector(x) 
  [1] 1 2 

>     MM> We recently had the following posting on R-devel
>     MM> https://stat.ethz.ch/pipermail/r-devel/2005-October/034962.html
>     MM> (Subject: [Rd] all.equal() improvements (PR#8191))

> I'm testing the first part of Andy's proposition
> {the 2nd part was about making the result strings more informative for
>  the case where all.equal() does *not* return TRUE}.

Excellent, thank you for digging into this, Martin!

> t() drops dimnames when they are list(NULL,NULL) 
> and has been doing so at least since R version 1.0.0 :
> 
>  x <- cbind(1:2, 2:1); dimnames(x) <- list(NULL, NULL) 
>  identical(x, t(x))  ## -> FALSE !
>  str(t(x)) # "no dimnames" (i.e. dimnames(x) === NULL)
> 
> Now I'm looking into changing that one....

Interesting.  FYI, my PR#8192 "subscripting sometimes loses names"
hack does NOT fix or change that, I get the same result as you do
above - t(x) is losing dimnames in that case.

  http://bugs.r-project.org/cgi-bin/R/wishlist?id=8192

S-Plus 6.2.1 (or at least my somewhat patched version of it) does not
seem to have that bug:

  > x <- cbind(1:2, 2:1); dimnames(x) <- list(NULL, NULL)  
  > identical(x, t(x)) 
  [1] T 

  > dimnames(x) 
  [[1]]: 
  character(0) 
  [[2]]: 
  character(0) 

  > dimnames(t(x)) 
  [[1]]: 
  character(0) 
  [[2]]: 
  character(0) 

-- 
Andrew Piskorski <atp at piskorski.com>
http://www.piskorski.com/



More information about the R-devel mailing list