Generic function to convert R objects to HDF5 format
Source:R/all_generic.R
, R/io_h5_generic.R
as_h5-methods.Rd
A generic function for converting various types of R objects to HDF5 format, providing a standardized interface for serialization to HDF5.
Usage
as_h5(object, file, ...)
# S4 method for class 'NeuroVec'
as_h5(
object,
file = NULL,
data_type = "FLOAT",
chunk_dim = c(4, 4, 4, dim(object)[4]),
compression = 6
)
# S4 method for class 'LatentNeuroVec'
as_h5(object, file = NULL, data_type = "FLOAT", compression = 6)
# S4 method for class 'LabeledVolumeSet'
as_h5(
object,
file,
mask,
labels,
compression = 4,
dtype = hdf5r::h5types$H5T_NATIVE_DOUBLE,
chunk_size = 1024,
header_values = list()
)
# S4 method for class 'NeuroVecSeq'
as_h5(object, file = NULL, ...)
Arguments
- object
The R object to convert to HDF5 (e.g., a
NeuroVol
orNeuroVec
).- file
The path to the HDF5 file to create or modify.
- ...
Additional arguments specific to the particular method (see Details).
- data_type
For NeuroVec/LatentNeuroVec methods: Storage type (e.g., "FLOAT"). Default "FLOAT"
- chunk_dim
For NeuroVec method: Chunk dimensions. Default depends on input dimensions
- compression
For all methods: Integer compression level [0..9]. Default varies by method
- mask
For LabeledVolumeSet method: The mask to use (LogicalNeuroVol)
- labels
For LabeledVolumeSet method: Character vector of labels
- dtype
For LabeledVolumeSet method: HDF5 data type for values. Default H5T_NATIVE_DOUBLE
- chunk_size
For LabeledVolumeSet/list methods: Integer chunk size for HDF5. Default 1024
- header_values
For LabeledVolumeSet method: List of additional header values
- scan_names
For list method: Character vector of scan names
- clusters
For list method: ClusteredNeuroVol with cluster IDs
- scan_metadata
For list method: List of metadata lists, one per scan
- cluster_metadata
For list method: Optional data.frame with cluster descriptions
- summary_only
For list method: If TRUE, save summary data only
Value
An object representing the HDF5 storage, typically of a class
corresponding to the input type (e.g., H5NeuroVol
for NeuroVol
input,
H5NeuroVec
for NeuroVec
input).
Methods
signature(object = "NeuroVec")
Creates an HDF5 file from a 4D NeuroVec object. Additional parameters:
data_type
Storage type (e.g., "FLOAT"). Default "FLOAT"
chunk_dim
Chunk dimensions. Default depends on input dimensions
compression
Integer [0..9], default 6
Returns an H5NeuroVec referencing the new HDF5 file.
signature(object = "LatentNeuroVec")
Saves a LatentNeuroVec to an HDF5 file in BasisEmbeddingSpec format. Additional parameters:
data_type
Storage type (e.g., "FLOAT"). Default "FLOAT"
compression
Integer [1..9], default 6
Returns an HDF5 file object.
signature(object = "LabeledVolume")
Saves a LabeledVolume to an HDF5 file. Additional parameters:
mask
The mask to use (LogicalNeuroVol)
labels
Character vector of labels
compression
Integer [0..9], default 4
dtype
HDF5 data type for values. Default H5T_NATIVE_DOUBLE
chunk_size
Integer chunk size for HDF5, default 1024
header_values
List of additional header values
Returns an HDF5 file object.
signature(object = "list")
Writes a cluster-based time-series dataset to an HDF5 file. Additional parameters:
scan_names
Character vector of scan names
mask
LogicalNeuroVol for 3D geometry
clusters
ClusteredNeuroVol with cluster IDs
scan_metadata
List of metadata lists, one per scan
cluster_metadata
Optional data.frame with cluster descriptions
summary_only
Logical; if TRUE, store only summary data
compression
Integer [0..9], default 4
chunk_size
Chunk dimension for 2D writes, default 1024
Returns an HDF5-backed object representing the clustered dataset (e.g., H5ParcellatedMultiScan).
signature(object = "NeuroVecSeq")
Writes a sequence of NeuroVec objects (multiple 4D scans) to a single HDF5 file. All NeuroVec objects must have the same spatial dimensions. Additional parameters:
scan_names
Optional character vector of scan names. If NULL, uses "scan_1", "scan_2", etc.
data_type
Character string: "FLOAT" (default), "DOUBLE", or "INT"
chunk_dim
Numeric vector specifying chunk sizes. If NULL, uses time-optimized chunking
compression
Integer [0..9], default 6
scan_metadata
Optional named list of metadata lists, one per scan
Returns the file path of the created HDF5 file.