Writes a LatentNeuroVec
to an HDF5 file with optional compression.
Usage
# S4 method for class 'LatentNeuroVec,character,missing,missing'
write_vec(x, file_name, compression = 9, nbit = FALSE)
Details
This function saves:
basis
matrixloadings
matrixoffset
vectorSpatial metadata
Mask information
all inside an HDF5 file for future loading.
See also
read_vec
for reading back the file.
Examples
if (FALSE) { # \dontrun{
if (requireNamespace("neuroim2", quietly = TRUE) &&
requireNamespace("hdf5r", quietly = TRUE) &&
requireNamespace("Matrix", quietly = TRUE) &&
exists("write_vec", where = "package:neuroim2") &&
!is.null(fmristore:::create_minimal_LatentNeuroVec)) {
lnv <- NULL
temp_h5_file <- NULL
tryCatch({
# Create a minimal LatentNeuroVec
lnv <- fmristore:::create_minimal_LatentNeuroVec(
space_dims = c(3L, 3L, 2L),
n_time = 5L,
n_comp = 2L
)
# Create a temporary file for output
temp_h5_file <- tempfile(fileext = ".h5")
# Write the LatentNeuroVec to HDF5
write_vec(lnv, temp_h5_file, compression = 6)
# Verify file was created
if (file.exists(temp_h5_file)) {
cat("Successfully wrote LatentNeuroVec to:", temp_h5_file, "\n")
}
}, error = function(e) {
message("write_vec example failed: ", e$message)
}, finally = {
# Clean up temporary file
if (!is.null(temp_h5_file) && file.exists(temp_h5_file)) {
unlink(temp_h5_file)
}
})
}
} # }