realize | R Documentation |
realize()
is an S4 generic function.
The default realize()
method handles the array case. It will
realize the array-like object (typically a DelayedArray object)
in memory or on disk, depending on the realization backend specified
via its BACKEND
argument,
realize(x, ...)
## S4 method for signature 'ANY'
realize(x, BACKEND=getAutoRealizationBackend())
x |
An array-like object (typically a DelayedArray object) for the default method. Other types of objects can be supported via additional methods.
For example, the SummarizedExperiment package defines a
method for SummarizedExperiment objects (see
|
... |
Additional arguments passed to methods. |
BACKEND |
|
The default realize()
method realizes an array-like object x
in memory if BACKEND
is NULL
, otherwise on disk.
Note that, when BACKEND
is not NULL
, x
gets realized as
a "pristine" DelayedArray object (e.g. an HDF5Array
object), that is, as a DelayedArray object that carries no delayed
operations. This means that, if x
is itself a DelayedArray
object, then the returned object is another DelayedArray object
semantically equivalent to x
where the delayed operations carried
by x
have been realized.
A "pristine" DelayedArray object if BACKEND
is
not NULL
.
Otherwise, an ordinary matrix or array, or a SparseArray object.
getAutoRealizationBackend
and
setAutoRealizationBackend
for getting and setting
the automatic realization backend.
DelayedArray objects.
RleArray objects.
HDF5Array objects in the HDF5Array package.
SparseArray objects implemented in the SparseArray package.
array objects in base R.
## ---------------------------------------------------------------------
## In-memory realization
## ---------------------------------------------------------------------
a <- array(1:24, dim=4:2)
realize(a, BACKEND=NULL) # no-op
A <- DelayedArray(a)
realize(log(A), BACKEND=NULL) # same as 'as.array(log(A))'
## Sanity checks:
stopifnot(identical(realize(a, BACKEND=NULL), a))
stopifnot(identical(realize(log(A), BACKEND=NULL), log(a)))
## ---------------------------------------------------------------------
## On-disk realization
## ---------------------------------------------------------------------
library(HDF5Array)
realize(log(A), BACKEND="HDF5Array") # same as 'as(log(A), "HDF5Array")'
## ---------------------------------------------------------------------
## Omitting the 'BACKEND' argument
## ---------------------------------------------------------------------
## When 'BACKEND' is not specified, the "automatic realization backend"
## is used. This backend is controlled via setAutoRealizationBackend().
toy_h5 <- system.file("extdata", "toy.h5", package="HDF5Array")
h5ls(toy_h5)
M1 <- HDF5Array(toy_h5, "M1")
M2 <- HDF5Array(toy_h5, "M2")
M3 <- rbind(log(M1), t(M2)) + 0.5
M3
## Set the "automatic realization backend" to NULL for in-memory
## realization (as ordinary array or SparseArray object):
setAutoRealizationBackend(NULL)
m3 <- realize(M3) # in-memory realization
registeredRealizationBackends()
setAutoRealizationBackend("RleArray")
realize(M3) # realization as RleArray object
setAutoRealizationBackend("HDF5Array")
realize(M3) # on-disk realization (as HDF5Array object)
setAutoRealizationBackend() # restore default (NULL)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.