From roebuck at mdanderson.org  Wed May 10 13:28:43 2006
From: roebuck at mdanderson.org (Paul Roebuck)
Date: Wed, 10 May 2006 06:28:43 -0500 (CDT)
Subject: [Rd] array dimname argument (was Re: YA S4 method dispatch question)
In-Reply-To: <6phy7xaczoa.fsf@gopher3.fhcrc.org>
References: <Pine.OSF.4.58.0605091347380.485682@wotan.mdacc.tmc.edu>
	<6phy7xaczoa.fsf@gopher3.fhcrc.org>
Message-ID: <Pine.OSF.4.58.0605100454070.519265@wotan.mdacc.tmc.edu>

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)



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