Dear R-Help readers,

I am writing to ask about some behavior of base::dimnames() that surprised
me. If I create an array with one of its dimensions = 1, and then try to
assign names to that dimension, I get an error unless I name one of the
other dimensions first. For example:

> temp1 = array(NA, c(3,2,1))
> dimnames(temp1)[[3]] = "test"

results in the error: "Error in dimnames(temp1)[[3]] = "test" : 'dimnames'
must be a list"

However, the following works:

> temp1 = array(NA, c(3,2,1))
> dimnames(temp1)[[2]] = c("a","b")
> dimnames(temp1)[[3]] = "test"

I found an explanation of what is happening on stackoverflow (
http://stackoverflow.com/questions/12578461/r-dimnames-of-matrix-strange-behaviour/42915723),
however, I didn't see any explanation of why this behavior is
intended/desirable. Moreover, it recently caused a problem in a place where
I couldn't easily work around it, without submitting edits to or forking
someone else's R package. Is there any possibility that this behavior is a
bug that could be fixed, or is it something I should learn to live with?

Thanks,
Doug

-- 

Typed from a mobile device - apologies for typos and brevity.

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to