| RleArray-class {DelayedArray} | R Documentation |
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.
RleArray(rle, dim, dimnames=NULL, chunksize=NULL) # constructor function
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 |
chunksize |
Experimental. Don't use! |
RleArray extends DelayedArray. All the operations available on DelayedArray objects work on RleArray objects.
Rle objects in the S4Vectors package.
DelayedArray objects.
DelayedArray-utils for common operations on DelayedArray objects.
realize for realizing a DelayedArray object in memory
or on disk.
HDF5Array objects in the HDF5Array package.
DataFrame objects in the S4Vectors package.
array objects in base R.
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))