Skip to contents

Save an image catalog to a JSON file for later retrieval with read_catalog().

Usage

write_catalog(catalog, file)

Arguments

catalog

An image_catalog object.

file

Output file path (should end in .json).

Value

Invisibly returns the file path.

Examples

# Build a tiny study tree with empty placeholder files
root <- tempfile("study_")
for (s in c("01", "02")) {
  d <- file.path(root, paste0("sub-", s))
  dir.create(d, recursive = TRUE)
  invisible(file.create(file.path(d, c("cope1.nii.gz", "varcope1.nii.gz"))))
}
catalog <- image_catalog(root, "sub-*/*.nii.gz",
                         path_regex = "sub-(?<subject>[^/]+)")

manifest <- tempfile(fileext = ".json")
write_catalog(catalog, manifest)
file.exists(manifest)
#> [1] TRUE

unlink(c(manifest, root), recursive = TRUE)