RleArray-class: RleArray objects

Description Usage Arguments Details See Also Examples

Description

The RleArray class is an array-like container where the values are stored in a run-length encoding format. RleArray objects support delayed operations and block processing.

Usage

1
RleArray(rle, dim, dimnames=NULL, chunksize=NULL)  # constructor function

Arguments

rle

An Rle object.

dim

The dimensions of the object to be created, that is, an integer vector of length one or more giving the maximal indices in each dimension.

dimnames

Either NULL or the names for the dimensions. This must a list of length the number of dimensions. Each list element must be either NULL or a character vector along the corresponding dimension.

chunksize

Experimental. Don't use!

Details

RleArray extends DelayedArray. All the operations available on DelayedArray objects work on RleArray objects.

See Also

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
rle <- Rle(sample(6L, 500000, replace=TRUE), 8)
a <- array(rle, dim=c(50, 20, 4000))  # array() expands the Rle object
                                      # internally with as.vector()

A <- RleArray(rle, dim=c(50, 20, 4000))  # Rle object is NOT expanded
A

object.size(a)
object.size(A)

stopifnot(identical(a, as.array(A)))

as(A, "Rle")  # deconstruction

toto <- function(x) (5 * x[ , , 1] ^ 3 + 1L) * log(x[, , 2])
b <- toto(a)
head(b)

B <- toto(A)  # very fast! (operations are delayed)
B

stopifnot(identical(b, as.array(B)))

cs <- colSums(b)
CS <- colSums(B)
stopifnot(identical(cs, CS))

## Coercion of a DelayedMatrix object to DataFrame produces a DataFrame
## object with Rle columns:
as(B, "DataFrame")

## Coercion of an RleList object to RleArray only works if all the list
## elements in the RleList have the same length. Column names are taken
## from the names of the list elements.
rle_list <- RleList(A=Rle(sample(3L, 100, replace=TRUE)),
                    B=Rle(sample(3L, 100, replace=TRUE)))
C <- as(rle_list, "RleArray")
C
stopifnot(identical(as(C, "RleList"), rle_list))

DelayedArray documentation built on Nov. 1, 2018, 2:27 a.m.