# A single file NIFTI image (the default):
data <- array(1:24, dim = c(4, 3, 2))
nii_file <- tempfile(fileext = ".nii")
write.nifti1(nii_file, data)
# A NIFTI v1 pair, i.e. a header plus a separate data file. Ask for a pair
# header by passing 'pair = TRUE' (this is passed on to the header generator):
write.nifti1(tempfile(fileext = ".hdr"), data, pair = TRUE)
# The NIFTI v1 pair files can be read back with the volume reader:
hdr_file <- tempfile(fileext = ".hdr")
write.nifti1(hdr_file, data, pair = TRUE)
vol <- read.fs.volume(hdr_file, with_header = TRUE)
print(dim(vol$data))
Run the code above in your browser using DataLab