[Rd] cannot assign to NULL dimnames (PR#1042)

ripley@stats.ox.ac.uk ripley@stats.ox.ac.uk
Tue, 7 Aug 2001 21:33:10 +0200 (MET DST)


On Tue, 7 Aug 2001 htang@hpl.hp.com wrote:

> Full_Name: Hsiu-Khuern Tang
> Version: 1.3.0
> OS: GNU/Linux (Debian unstable)
> Submission from: (NULL) (192.6.19.124)
>
>
> Hi all,
>
>     I am not sure this is a bug rather than an intentional design, but here
> goes:

None of the above.

> If I do
>
> > a <- matrix(1:4, nrow=2)
> > dimnames(a)[[1]] <- c("a", "b")
>
> I get the following error message because dimnames(a) is NULL:
>
> Error: more elements supplied than there are to replace

Which is a correct error message.

> What is the proper way to do this?

rownames(a) <- c("a", "b")


> I know this works:
>
> > dimnames(a) <- list(c("a", "b"), NULL)
>
>    Incidentally, in SPlus, I can assign to NULL dimnames.


Really?  Your own example fails in the versions I have to hand:

S-PLUS 3.4 gives

> dimnames(a)[[1]] <- c("a", "b")
Error in dimnames(a) <- .A0: data of mode character can't be used as
dimnames
        (need a list)
In addition: Warning messages:
  Replacement length not a multiple of number of elements to replace in:
.A0[[1
        ]] <- .A1
Dumped

and S-PLUS 6.0 gives

> dimnames(a)[[1]] <- c("a", "b")
Problem in dimnames(a) <- .A0: Invalid length (1) for dimnames attribute;
needs to be 2

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._