Check whether each object in a directory is valid by calling validateObject
on each non-child object.
validateDirectory(dir, legacy = NULL, ...)
String containing the path to a directory with subdirectories populated by saveObject
.
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.
Character vector of the paths inside dir
that were validated, invisibly.
If any validation failed, an error is raised.
We assume that the process of validating an object will call validateObject
on any child objects.
This allows us to skip explicit calls to validateObject
on each component of a complex object.
# 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/Rtmp6XG2G9/file221617545ff/bar'; metadata should be a JSON object