R-alpha: R-0.15: problem with dimnames<-()

Kurt Hornik (hornik@ci.tuwien.ac.at)
Mon, 30 Dec 1996 14:32:31 +0100


Date: Mon, 30 Dec 1996 14:32:31 +0100
Message-Id: <199612301332.OAA00674@aragorn.ci.tuwien.ac.at>
From: Kurt Hornik <hornik@ci.tuwien.ac.at>
To: r-testers@stat.math.ethz.ch
Subject: R-alpha: R-0.15:  problem with dimnames<-()

The following problem exists:

R> x <- matrix(1:4, 2, 2)
R> x
     [,1] [,2]
[1,]    1    3
[2,]    2    4
R> dimnames(x)
NULL
R> rownames(x) <- NULL
R> dimnames(x)
[[1]]
NULL

[[2]]
NULL
R> dimnames(x)[[1]] <- NULL
Error: dimnames: number of dimensions must equal number of names
R> dimnames(x)
[[1]]
NULL

[[2]]
NULL

R> dimnames(x)[[2]] <- NULL
Error: dimnames: number of dimensions must equal number of names
R> dimnames(x)
[[1]]
NULL


Hmm ... it would be nicer if there were no errors.   rownames() and
colnames() are `nice':

R> rownames(x) <- NULL
R> dimnames(x)
[[1]]
NULL

[[2]]
NULL

R> colnames(x) <- NULL
R> dimnames(x)
[[1]]
NULL

[[2]]
NULL

(I am not sure whether the `new' interpretation of NULL assignments
apply here or not).

In any case, there is at least one `real' problem with the above:

R> y <- matrix(rnorm(20), 10, 2)
R> lm(y ~ 1)

Call:
lm(formula = y ~ 1)

Coefficients:
                  [,1]      [,2]
(Intercept) -0.1345775 0.6649173

R> colnames(y) <- c("A", "B")
R> lm(y ~ 1)
Error: dimnames: number of dimensions must equal number of names

This comes from

	dimnames(z$effects)[[1]] <- NULL

in the code for lm.fit() in src/library/base/funs/lm.   Replacing the
above by

	rownames(z$effects) <- NULL

fixes the problem.

-k


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
r-testers mailing list -- For info or help, send "info" or "help",
To [un]subscribe, send "[un]subscribe"
(in the "body", not the subject !)  To: r-testers-request@stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-