Skip to contents

Check that the catalog has consistent file coverage across subjects and report any missing or extra files.

Usage

# S3 method for class 'image_catalog'
validate(x, by = "subject", expect = NULL, ...)

Arguments

x

An image_catalog object.

by

Column name to group by for consistency check. Default "subject".

expect

Optional character vector of expected file basenames per subject.

...

Additional arguments (ignored).

Value

A catalog_validation_report object.

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

report <- validate(catalog)
print(report)
#> Catalog Validation Report
#>   Files: 4
#>   Subjects: 2
#>   Status: VALID

report <- validate(catalog, expect = c("cope1.nii.gz", "varcope1.nii.gz"))

# Remove one file to see an inconsistency being reported
invisible(file.remove(file.path(root, "sub-02", "varcope1.nii.gz")))
catalog <- image_catalog(root, "sub-*/*.nii.gz",
                         path_regex = "sub-(?<subject>[^/]+)")
validate(catalog)
#> Catalog Validation Report
#>   Files: 3
#>   Subjects: 2
#>   Status: ISSUES FOUND
#>     - Uneven file counts across groups:
#>         01: 2 files
#>         02: 1 files
#>     - Inconsistent files across groups:
#>         02 missing: varcope1.nii.gz

unlink(root, recursive = TRUE)