array() ignores illegal non-list dimnames

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

array() ignores illegal non-list dimnames

R devel mailing list
Is there a reason that array() silently ignores dimnames that are not
a list but matrix() gives an error?

  > str(matrix(11:14, 2, 2, dimnames=c("Rows","Cols")))
  Error in matrix(11:14, 2, 2, dimnames = c("Rows", "Cols")) :
    'dimnames' must be a list
  > str(array(11:14, dim=c(2, 2), dimnames=c("Rows","Cols")))
   int [1:2, 1:2] 11 12 13 14

I noticed this in lhs:::geneticLHS, which has the line
            J <- array(NA, dim = c(n, k, pop), dimnames = c("points",
"variables", "hypercubes"))
where the non-list dimnames has no effect, and no warning or error.

Bill Dunlap
TIBCO Software
wdunlap tibco.com

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: array() ignores illegal non-list dimnames

Martin Maechler
>>>>> William Dunlap via R-devel <[hidden email]>
>>>>>     on Thu, 17 Dec 2015 14:40:18 -0800 writes:

    > Is there a reason that array() silently ignores dimnames
    > that are not a list but matrix() gives an error?

    >> str(matrix(11:14, 2, 2, dimnames=c("Rows","Cols")))
    > Error in matrix(11:14, 2, 2, dimnames = c("Rows", "Cols")) :
    > 'dimnames' must be a list

    >> str(array(11:14, dim=c(2, 2), dimnames=c("Rows","Cols")))
    > int [1:2, 1:2] 11 12 13 14

of course there must be a historical reason why this lapsus
happens, ;-)

but it is definitely not as intended, and I'll commit a fix for
R-devel and R-patched  "immediately".

    > I noticed this in lhs:::geneticLHS, which has the line
    > J <- array(NA, dim = c(n, k, pop), dimnames = c("points",
    > "variables", "hypercubes"))
    > where the non-list dimnames has no effect, and no warning or error.

so we will see some CRAN (and may off-CRAN) packages
producing errors after the change,
but indeed, these errors will be catching programming errors !

    > Bill Dunlap
    > TIBCO Software
    > wdunlap tibco.com

Thanks a lot, Bill!
Martin

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel