chunkify: Call a function on array chunks

Description Usage Arguments Details Value Note

View source: R/array_general.R

Description

chunkify creates subsets of an array according to various chunking schemes and performs the given function on these data chunks. The resulting array is identical to the result of a function call on the whole array.

Usage

1
chunkify(dat, fun, arg_list = NULL, chunks = NULL)

Arguments

dat

matrix or array with named dimnames

fun

name of the function (can be a character string). See Details.

arg_list

a list of parameters passed to fun

chunks

a named list which defines the chunking scheme. See Details.

Details

The main purpose of chunkify is twofold: 1) it can decrease memory load if a memory-intensive function is called on a large array; 2) it enables within-dimension computations (e.g. perform baseline correction separately for various levels of the trial dimension). The parameter chunks is a named list; each element must correspond to a named dimension of dat. If the list element contains one integer, it gives the number of chunks for the given dimension. If it contains as many elements as the length of the given dimension, it defines chunk code; i.e., which chunk the given level of the dimension belongs to. Otherwise, the list elements are expanded (recycled to the dimensions' length) and interpreted as chunk codes. fun must be a function which operates on arrays (or matrices), and returns a matrix or array with named dimensions. Chunking can be based only on those dimensions which are not affected by fun.

Value

An array (or vector/matrix); its shape and dimension names are identical to the return value of fun called on dat without chunking

Note

This function is experimental.


tdeenes/eegR documentation built on April 19, 2021, 4:17 p.m.