spray (version 1.0-6)

as.array: Coerce spray objects to arrays

Description

Coerces spray objects to arrays. Includes off-by-one functionality via option offbyone.

Usage

# S3 method for spray
as.array(x, offbyone=FALSE, compact=FALSE, ...)
# S3 method for spray
dim(x)

Arguments

x

spray object

offbyone

Boolean with default FALSE meaning to interpret the index entries as positions in their dimension, and TRUE meaning to add one to index values so that zero entries appear in the first place

compact

Boolean with default FALSE meaning to translate the spray as is, and TRUE meaning to add constants to each column of the index matrix so that the resulting array is as small as possible

...

Further arguments, currently ignored

Value

Returns an array of dimension dim(S). The “meat” of the function is

out <- array(0, dS) out[ind] <- value(S)

Details

Argument offbyone defaults to FALSE; but if it is set to TRUE, it effectively adds one from the index matrix, so a zero entry in the index matrix means the first position in that dimension.

After the subtraction, if performed, the function will not operate if any index is less than 1.

Examples

# NOT RUN {
M <- matrix(sample(0:4,28,replace=TRUE),ncol=4)
S <- spray(M,sample(7),addrepeats=TRUE)
A <- as.array(S,offbyone=TRUE) 



S <- spray(matrix(sample(1:4,28,replace=TRUE),ncol=4),sample(7))
A <- as.array(S)   # S has no zero indices

stopifnot(all(S[index(S),drop=TRUE] == A[index(S)])) 
# }