[Rd] Behaviour of array() (PR#7790)

mjw at celos.net mjw at celos.net
Thu Apr 14 11:54:21 CEST 2005


Slightly surprising behaviour from array() when passed dim
arguments slightly below integer values.  Example:

    dd <- c(10.0, 9.9)
    a  <- array(numeric(1), dd)

produces an error (R 2.0.1, NetBSD 2.0):

    Error in array(numeric(1), dd) : dim<- : dims [product 90] 
    do not match the length of object [99]

Problem is that dim is coerced to integer before product in
dimgets() (src/main/attrib.c, line 711), but the product is
found from floating point values then converted to integer
when replicating the data argument (library/base/R/array.R).

This bit me with a dimension 'invisibly' less than an
integer (along the lines of 10 - 5e-7, so printed as 10).
If this needs fixing (current behaviour is sort of
"correct", but probably not usually what you want), the
simplest thing is to say

    dim <- as.integer(dim)

at the start of array() in array.R.

Mark <><



More information about the R-devel mailing list