Skip to contents

Merge a data frame with the catalog metadata by a key column.

Usage

join_meta(catalog, data, by, suffix = ".external")

Arguments

catalog

An image_catalog object.

data

External data.frame to join.

by

Column name(s) for joining (must exist in both catalog$metadata and data).

suffix

Suffix for duplicate column names from data. Default ".external".

Value

Updated image_catalog.

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>[^/]+)")

demographics <- data.frame(subject = c("01", "02"), age = c(25, 30))
catalog <- join_meta(catalog, demographics, by = "subject")
catalog$metadata[, c("basename", "subject", "age")]
#>          basename subject age
#> 1    cope1.nii.gz      01  25
#> 2 varcope1.nii.gz      01  25
#> 3    cope1.nii.gz      02  30
#> 4 varcope1.nii.gz      02  30

unlink(root, recursive = TRUE)