Convenience wrapper that inspects the file header(s) and dispatches to the
appropriate specialized reader: read_vol for a single 3D file,
read_vec for 4D data or for any multi-file input, or
read_hyper_vec for 5D data.
Arguments
- file_name
Character vector of one or more file paths.
- type
One of
"auto","vol","vec", or"hyper"to override header-based dispatch.- index
Integer volume index. Used as the single-volume selector for
read_vol(when dispatching to it) and, whenindicesisNULL, forwarded toread_vecasindicesso you can pull out a subset of time points while still receiving aNeuroVec.- indices
Optional integer vector of sub-volume indices forwarded to
read_vec. Takes precedence overindex.- mask
Optional spatial mask passed through to the vector or hyper-vector readers. Ignored by
read_vol.- mode
IO mode forwarded to
read_vec; see that function for details. Ignored for 3D and 5D dispatch.
Value
The return type depends on dispatch:
3D dispatch (single effectively-3D file, or
type = "vol"): aDenseNeuroVol.4D dispatch (single 4D file, or
type = "vec"with one file): aNeuroVec(concrete subclass depends onmode).Multi-file dispatch (
length(file_name) > 1, ortype = "vec"with multiple files): aNeuroVecSeq, which extendsNeuroVecbut stores each file as a distinct segment rather than concatenating into a single contiguous 4D array. Mixed 3D/4D inputs are allowed; each 3D file contributes one time point to the sequence.5D dispatch (single 5D file, or
type = "hyper"): aNeuroHyperVec.
Details
Auto-dispatch (type = "auto") uses the following rules:
length(file_name) > 1: always routed toread_vec, so the result is aNeuroVecSeqregardless of whether the individual files are 3D, 4D, or a mix. Seeread_vecfor the return-type details.Single file with a 5th dimension
> 1: routed toread_hyper_vec, returning aNeuroHyperVec.Single file with a 4th dimension
> 1: routed toread_vec, returning aNeuroVec. Ifindexis supplied (andindicesis not), it is forwarded asindicesso you can pull out a subset while still getting aNeuroVecback.Single effectively-3D file (either truly 3D or 4D with
dim[4] == 1): routed toread_vol, returning aDenseNeuroVol.
Explicit type values bypass header inspection:
type = "vol": requires a single file; always returns aDenseNeuroVol. Theindexargument picks the sub-volume when the file is 4D.type = "vec": forwards toread_vec. Multi-file input yields aNeuroVecSeq. A single 3D file is promoted to aNeuroVecwithdim[4] == 1.type = "hyper": requires a single file; returns aNeuroHyperVec.
Examples
# 3D file -> DenseNeuroVol
vol <- read_image(system.file("extdata", "global_mask2.nii.gz", package = "neuroim2"))
# 4D file -> NeuroVec
vec <- read_image(system.file("extdata", "global_mask_v4.nii", package = "neuroim2"))
# Multiple files (any mix of 3D and 4D) -> NeuroVecSeq
fn <- system.file("extdata", "global_mask_v4.nii", package = "neuroim2")
seq_vec <- read_image(c(fn, fn))
class(seq_vec) # "NeuroVecSeq"
#> [1] "NeuroVecSeq"
#> attr(,"package")
#> [1] "neuroim2"