Check whether each object in a directory is valid by calling validateObject on each non-nested object.

validateDirectory(dir, legacy = NULL, ...)

Arguments

dir

String containing the path to a directory with subdirectories populated by saveObject.

legacy

Logical scalar indicating whether to validate a directory with legacy objects (created by the old stageObject). If NULL, this is auto-detected from the contents of dir.

...

Further arguments to use when legacy=TRUE, for back-compatibility only.

Value

Character vector of the paths inside dir that were validated, invisibly. If any validation failed, an error is raised.

Details

We assume that the process of validating an object will call validateObject on any nested objects. This allows us to skip explicit calls to validateObject on each component of a complex object.

Author

Aaron Lun

Examples

# Mocking up an object:
library(S4Vectors)
ncols <- 123
df <- DataFrame(
    X = rep(LETTERS[1:3], length.out=ncols),
    Y = runif(ncols)
)
df$Z <- DataFrame(AA = sample(ncols))

# Mocking up the directory:
tmp <- tempfile()
dir.create(tmp, recursive=TRUE)
saveObject(df, file.path(tmp, "foo"))

# Checking that it's valid:
validateDirectory(tmp)

# Adding an invalid object:
dir.create(file.path(tmp, "bar"))
write(file=file.path(tmp, "bar", "OBJECT"), '[ "WHEEE" ]')
try(validateDirectory(tmp))
#> Error in value[[3L]](cond) : 
#>   failed to validate 'bar'; failed to read the OBJECT file at '/tmp/RtmpChCVYK/file26c4d533191/bar'; metadata should be a JSON object