chunk_apply {matter}R Documentation

Apply Functions Over Chunks of a Vector or Matrix

Description

Perform equivalents of lapply and apply, 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 IO operations.

Usage

chunk_apply(X, FUN, MARGIN, ..., simplify = FALSE,
    chunks = NA, view = c("element", "chunk"),
    attr = list(), alist = list(), outfile = NULL,
    verbose = FALSE, BPREDO = list(), BPPARAM = bpparam())

Arguments

X

A list, vector, or matrix. These may be any class that implements suitable methods for [, [[, dim, and length().

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 X has dimnames set.

...

Additional arguments to be passed to FUN.

simplify

Should the result be simplified into a vector, matrix, or higher dimensional array?

chunks

The number of chunks to use. If NA (the default), this is inferred from chunksize(X) for matter objects, or from getOption("matter.default.chunksize") for non-matter classes. For IO-bound operations, using fewer chunks will often be faster, but use more memory.

view

What should be passed as the argment to FUN: "element" means the vector element, row, or column are passed (same as the behavior of lapply and apply), and "chunk" means to pass the entire chunk.

attr

A list of attributes that will be attached to the argument passed to FUN as-is.

alist

A list of vector-like attributes that will be attached to the argument passed to FUN, subsetted to the current elements.

outfile

If non-NULL, a file path where the results should be written as they are processed. Not implemented yet.

verbose

Should user messages be printed with the current chunk being processed?

BPREDO

See documentation for bplapply.

BPPARAM

An optional instance of BiocParallelParam. See documentation for bplapply.

Value

Typically, a list if simplify=FALSE. Otherwise, the results may be coerced to a vector or array.

Author(s)

Kylie A. Bemis

See Also

lapply, apply

Examples

register(SerialParam())

set.seed(1)
x <- matrix(rnorm(1000^2), nrow=1000, ncol=1000)

out <- chunk_apply(x, mean, 1, chunks=20, verbose=TRUE)

[Package matter version 1.12.0 Index]