| DelayedArray-utils {DelayedArray} | R Documentation |
Common operations on DelayedArray objects.
The operations currently supported on DelayedArray objects are:
Delayed operations:
sweep
!
is.na, is.finite, is.infinite, is.nan
lengths
nchar, tolower, toupper,
grepl, sub, gsub
pmax2 and pmin2
t
rbind and cbind (documented in DelayedArray)
statistical functions like dnorm, dbinom, dpois,
and dlogis (for the Normal, Binomial, Poisson, and Logistic
distribution, respectively) and related functions (documented in
DelayedArray-stats)
Block-processed operations:
anyNA, which
all the members of the Summary group
mean
apply
matrix multiplication (%*%) of an ordinary matrix by a DelayedMatrix object
matrix row/col summarization [DelayedMatrix objects only]:
rowSums, colSums, rowMeans, colMeans,
rowMaxs, colMaxs, rowMins, colMins,
rowRanges, and colRanges
is.na, !,
mean, apply,
and %*% in the base package for the
corresponding operations on ordinary arrays or matrices.
rowSums in the base package and
rowMaxs in the matrixStats package
for row/col summarization of an ordinary matrix.
setRealizationBackend for how to set a
realization backend.
writeHDF5Array in the HDF5Array
package for writing an array-like object to an HDF5 file and other
low-level utilities to control the location of automatically created
HDF5 datasets.
DelayedArray objects.
DelayedArray-stats for statistical functions on DelayedArray objects.
HDF5Array objects in the HDF5Array package.
S4groupGeneric in the methods package
for the members of the Ops,
Math, and Math2 groups.
array objects in base R.
library(HDF5Array)
toy_h5 <- system.file("extdata", "toy.h5", package="HDF5Array")
h5ls(toy_h5)
M1 <- HDF5Array(toy_h5, "M1")
range(M1)
M1 >= 0.5 & M1 < 0.75
log(M1)
M2 <- HDF5Array(toy_h5, "M2")
pmax2(M2, 0)
sweep(M2, 2, colMeans(M2))
M3 <- rbind(M1, t(M2))
M3
## ---------------------------------------------------------------------
## MATRIX MULTIPLICATION
## ---------------------------------------------------------------------
## Matrix multiplication is not delayed: the output matrix is realized
## block by block. The current "realization backend" controls where
## realization happens e.g. in memory if set to NULL or in an HDF5 file
## if set to "HDF5Array". See '?realize' for more information about
## "realization backends".
## The output matrix is returned as a DelayedMatrix object with no delayed
## operations on it. The exact class of the object depends on the backend
## e.g. it will be HDF5Matrix with "HDF5Array" backend.
m <- matrix(runif(50000), ncol=nrow(M1))
## Set backend to NULL for in-memory realization:
setRealizationBackend()
P1 <- m %*% M1
P1
## Set backend to HDF5Array for realization in HDF5 file:
setRealizationBackend("HDF5Array")
## With the HDF5Array backend, the output matrix will be written to an
## automatic location on disk:
getHDF5DumpFile() # HDF5 file where the output matrix will be written
lsHDF5DumpFile()
P2 <- m %*% M1
P2
lsHDF5DumpFile()
## Use setHDF5DumpFile() and setHDF5DumpName() from the HDF5Array package
## to control the location of automatically created HDF5 datasets.
stopifnot(identical(as.array(P1), as.array(P2)))
## ---------------------------------------------------------------------
## MATRIX ROW/COL SUMMARIZATION
## ---------------------------------------------------------------------
rowSums(M1)
colSums(M1)
rowMeans(M1)
colMeans(M1)
rmaxs <- rowMaxs(M1)
cmaxs <- colMaxs(M1)
rmins <- rowMins(M1)
cmins <- colMins(M1)
rranges <- rowRanges(M1)
cranges <- colRanges(M1)
stopifnot(identical(cbind(rmins, rmaxs, deparse.level=0), rranges))
stopifnot(identical(cbind(cmins, cmaxs, deparse.level=0), cranges))