| write.cifti | R Documentation |
Write a data matrix and its axes to a CIFTI-2 file, i.e. a NIFTI-2 file
with the CIFTI-2 XML in a header extension. The axes describe what the matrix
dimensions contain; they can be given explicitly (see the cifti.axis.*() functions),
taken from a template file (recommended for real data, see
cifti.axis.from.template), or both.
The file type (and thus the NIFTI intent code that identifies it) follows from the
axes: a scalars dimension and a brain model dimension make a .dscalar file, a series
dimension and a brain model dimension a .dtseries file, and so on. If the file name
has one of the standard CIFTI extensions, the axes have to match it: a file named
.pdconn.nii whose dimensions are not (brain models, parcels) is an error, not a
warning, because the file name is the only hint that other software has about the
content.
write.cifti(filepath, data, axes = NULL, template = NULL, metadata = NULL)
filepath |
character string, the path of the file to write. |
data |
numeric or integer matrix or array, the data. The dimensions have to match
the sizes of the axes, and the order is the same as for |
axes |
list of axes, one per matrix dimension, or |
template |
character string (the path of a CIFTI-2 file), an |
metadata |
named character vector or named list, or |
the axes that were written, invisibly. The file is written as a side effect.
The data are written as 32 bit floating point values, which is what the reference implementations write for CIFTI-2 files (including for label files, whose keys are small integers). Values that need more than about 7 significant digits are rounded.
Other cifti functions:
cifti.axis.brain.models(),
cifti.axis.from.template(),
cifti.axis.labels(),
cifti.axis.parcels(),
cifti.axis.parcels.from.annot(),
cifti.axis.scalars(),
cifti.axis.series(),
cifti.brain.model.surface(),
cifti.brain.model.volume(),
cifti.dim.labels(),
cifti.file.type.for.axes(),
cifti.grayordinates(),
cifti.header.from.axes(),
cifti.label.table(),
cifti.parcel(),
cifti.parcels(),
cifti.series.info(),
cifti.structure.data(),
cifti.structures(),
cifti.volume(),
print.fs.cifti(),
print.fs.cifti.data(),
print.fs.connectome(),
read.cifti(),
read.cifti.header(),
read.cifti.rows(),
read.fs.connectome.cifti(),
write.fs.connectome.cifti(),
write.fs.morph.cifti(),
write.fs.parcellated.cifti(),
write.fs.parcellation.cifti(),
write.fs.series.cifti()
axis_brain <- cifti.axis.brain.models(list(
cifti.brain.model.surface("lh", 10L),
cifti.brain.model.surface("rh", 12L)))
data_matrix <- matrix(1:22, nrow = 1L)
out_file <- file.path(tempdir(), "tiny_written.dscalar.nii")
write.cifti(out_file, data_matrix, axes = list(cifti.axis.scalars("my data"), axis_brain))
## Not run:
# Write data with the mapping of an existing file (recommended for real data):
template <- "Conte69.MyelinAndCorrThickness.32k_fs_LR.dscalar.nii"
data_matrix <- read.cifti(template)$data
write.cifti("copy.dscalar.nii", data_matrix, template = template)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.