Description Usage Arguments Details Value Author(s) See Also Examples
Perform equivalents of apply
, lapply
, and mapply
, but over parallelized chunks of the data. This is most useful if accessing the data is potentially time-consuming, such as for file-based matter
objects. Operating on chunks reduces the number of I/O operations.
1 2 3 4 5 6 7 8 9 10 11 | chunk_apply(X, FUN, MARGIN, ..., simplify = FALSE,
chunks = NA, view = c("element", "chunk"),
attr = list(), alist = list(), pattern = NULL,
outfile = NULL, verbose = FALSE,
BPREDO = list(), BPPARAM = bpparam())
chunk_mapply(FUN, ..., MoreArgs = NULL, simplify = FALSE,
chunks = NA, view = c("element", "chunk"),
attr = list(), alist = list(), pattern = NULL,
outfile = NULL, verbose = FALSE,
BPREDO = list(), BPPARAM = bpparam())
|
X |
A list, vector, or matrix for |
FUN |
The function to be applied. |
MARGIN |
If the object is matrix-like, which dimension to iterate over. Must be 1 or 2, where 1 indicates rows and 2 indicates columns. The dimension names can also be used if |
MoreArgs |
A list of other arguments to |
... |
Additional arguments to be passed to |
simplify |
Should the result be simplified into a vector, matrix, or higher dimensional array? |
chunks |
The number of chunks to use. If |
view |
What should be passed as the argment to |
attr |
A named list of attributes that will be attached to the argument passed to |
alist |
A named list of vector-like attributes that will be attached to the argument passed to |
pattern |
A list of indices giving a pattern over which to apply |
outfile |
If non-NULL, a file path where the results should be written as they are processed. If specified, |
verbose |
Should user messages be printed with the current chunk being processed? |
BPREDO |
See documentation for |
BPPARAM |
An optional instance of |
When view = "element"
:
For vectors and lists, the vector is broken into some number of chunks according to chunks
. The individual elements of the chunk are then passed to FUN
.
For matrices, the matrix is chunked along rows or columns, based on the number of chunks
. The individual rows or columns of the chunk are then passed to FUN
.
In this way, the first argument of FUN
is analogous to using the base apply
and lapply
functions.
However, when view = "chunk"
:
In this situation, the entire chunk is passed to FUN
, and FUN
is responsible for knowing how to handle a sub-vector or sub-matrix of the original object. This may be useful if FUN
is already a function that could be applied to the whole object such as rowSums
or colSums
.
When this is the case, it may be useful to provide a custom simplify
function. Otherwise, the result will be returned as a list with length equal to the number of chunks, which must be post-processed to get into a desirable form.
For convenience to the programmer, several attributes are made available when view = "chunk"
.
"chunk_id":The index of the chunk currently being processed by FUN
.
"chunk_elt":The indices of the elements of the chunk, as rows/columns/elements in the original matrix/vector.
"pattern_id" (optional):The indices of the patterns that compose the current chunk.
"pattern_elt" (optional):The indices of the elements of the patterns, as rows/columns/elements in the original matrix/vector, that compose the current chunk.
The pattern
argument can be used to iterate over dependent elements of a vector, or dependent rows/columns of a matrix. This can be useful if the calculation for a particular row/column/element depends on the values of others.
When pattern
is provided, multiple rows/columns/elements will be passed to FUN
, even when view="element"
. Each element of the pattern
list should be a vector giving the indices that should be passed to FUN
.
This can be used to implement a rolling apply function.
Typically, a list if simplify=FALSE
. Otherwise, the results may be coerced to a vector or array.
Kylie A. Bemis
1 2 3 4 5 6 |
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.