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

Paul Roebuck roebuck at mdanderson.org
Wed May 10 13:28:43 CEST 2006


On Tue, 9 May 2006, Martin Morgan wrote:

> You won't like this ...;)
>
> return(drop(callGeneric(array(x,
>                               c(1, length(x)),
>                               val)
>                         )))
>
> i.e., 'val' is inside 'array'!
>
> I was discouraged from answering sooner by the complexity of your
> example; simplifying it might have provided an immediate answer...
>
> > x <- 1:8
> > foo(array(x, c(1,length(x)), val)
> +
>

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.

> x <- 1:8
> matrix(x, 1, length(x), dimnames = "argument used")
Error in matrix(x, 1, dimnames = "argument used") :
	'dimnames' must be a list
> array(x, c(1, length(x)), "argument silently ignored")
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
[1,]    1    2    3    4    5    6    7    8
> array
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)



More information about the R-devel mailing list