Skip to content
Prev 20576 / 63424 Next

array dimname argument (was Re: YA S4 method dispatch question)

On Tue, 9 May 2006, Martin Morgan wrote:

            
Geez... I should have noticed that. Thanks for the catch.
I am rather surprised (never having tried it before) that
array() silently disregards my unintentional dimname
argument.
Error in matrix(x, 1, dimnames = "argument used") :
	'dimnames' must be a list
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
[1,]    1    2    3    4    5    6    7    8
function (data = NA, dim = length(data), dimnames = NULL)
{
    data <- as.vector(data)
    vl <- prod(dim)
    if (length(data) != vl) {
        if (vl > .Machine$integer.max)
            stop("'dim' specifies too large an array")
        data <- rep(data, length.out = vl)
    }
    if (length(dim))
        dim(data) <- dim
    if (is.list(dimnames) && length(dimnames)) ##HERE##
        dimnames(data) <- dimnames
    data
}
<environment: namespace:base>

The matrix method performs no check prior to assigning
dimnames. Why doesn't array function the same way?

----------------------------------------------------------
SIGSIG -- signature too long (core dumped)