[Rd] dimnames(X)[[2]] <- foo fails (PR#1122)

Peter Dalgaard BSA p.dalgaard@biostat.ku.dk
09 Oct 2001 17:35:43 +0200


ripley@stats.ox.ac.uk writes:

> Since this works in recent S-PLUS and is not in the FAQ as a difference, I
> presume it is an unintentional one.  If it is intentional, this is for the
> wishlist that this be removed.
> 
> S-PLUS (6.0)
> > X <- matrix(1:4, 2, 2)
> > dimnames(X)[[2]] <- letters[1:2]
> > X
>      a b
> [1,] 1 3
> [2,] 2 4
> 
> R 1.3.1
> > X <- matrix(1:4, 2, 2)
> > dimnames(X)[[2]] <- letters[1:2]
> Error: more elements supplied than there are to replace
> > colnames(X) <- 1:2
> > dimnames(X)[[2]] <- letters[1:2]
> > X
>      a b
> [1,] 1 3
> [2,] 2 4
> 
> which is none too obvious an error message, and somewhat inconsistent.

Hmm. This is a consequence of 
> x<-NULL
> x[[2]]<- letters[1:2]
Error: more elements supplied than there are to replace

which S-PLUS does differently. However, I'm not sure we really want
this to change for the following reason:

> x<-NULL
> x[[2]]<- letters[1:2]
> x
$"":
NULL

$value:
[1] "a" "b"

> x<-NULL
> x[[2]]<-"1"
> x
[1] ""  "1"

Now what does this do if the array extent has length 1?

>  x <- matrix(1:2,2)
>  dimnames(X)[[2]] <- "a"
Problem in dimnames(X) <- .A0: Component 2 of dimnames has length 1, should be 2 
Use traceback() to see the call stack

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)             FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._