Create Data Chunks for matrix_dataset Objects
Source:R/fmri_dataset.R
data_chunks.matrix_dataset.Rd
This function creates data chunks for matrix_dataset objects. It allows for the retrieval of run-wise or sequence-wise data chunks, as well as arbitrary chunks.
Usage
# S3 method for matrix_dataset
data_chunks(x, nchunks = 1, runwise = FALSE, ...)
Arguments
- x
An object of class 'matrix_dataset'.
- nchunks
The number of data chunks to create. Default is 1.
- runwise
If TRUE, the data chunks are created run-wise. Default is FALSE.
- ...
Additional arguments.
Value
A list of data chunks, with each chunk containing the data, voxel indices, row indices, and chunk number.
Examples
# Create a matrix_dataset
# ... (see example for matrix_dataset)
# Create an iterator with 5 chunks
iter <- data_chunks(dset, nchunks=5)
#> Error in data_chunks(dset, nchunks = 5): object 'dset' not found
`%do%` <- foreach::`%do%`
y <- foreach::foreach(chunk = iter) %do% { colMeans(chunk$data) }
#> Error in eval(a, envir = extra, enclos = obj$evalenv): object 'iter' not found
length(y) == 5
#> Error in eval(expr, envir, enclos): object 'y' not found
# Create an iterator with 100 chunks
iter <- data_chunks(dset, nchunks=100)
#> Error in data_chunks(dset, nchunks = 100): object 'dset' not found
y <- foreach::foreach(chunk = iter) %do% { colMeans(chunk$data) }
#> Error in eval(a, envir = extra, enclos = obj$evalenv): object 'iter' not found
length(y) == 100
#> Error in eval(expr, envir, enclos): object 'y' not found
# Create a "runwise" iterator
iter <- data_chunks(dset, runwise=TRUE)
#> Error in data_chunks(dset, runwise = TRUE): object 'dset' not found
y <- foreach::foreach(chunk = iter) %do% { colMeans(chunk$data) }
#> Error in eval(a, envir = extra, enclos = obj$evalenv): object 'iter' not found
length(y) == 2
#> Error in eval(expr, envir, enclos): object 'y' not found