Validate unpacked packets. Over time, expect this function to become more fully featured, validating more.
Arguments
- expr
The query expression. A
NULLexpression matches everything.- name
Optionally, the name of the packet to scope the query on. This will be intersected with
scopearg and is a shorthand way of runningscope = list(name = "name")- action
The action to take on finding an invalid packet. See Details.
- root
The path to the root directory, or
NULL(the default) to search for one from the current working directory. This function does not require that the directory is configured for orderly, and can be anyoutpackroot (seeorderly_init()for details).
Details
The actions that we can take on finding an invalid packet are:
inform(the default): just print information about the problemorphan: mark the packet as orphaned within the metadata, but do not touch the files in your archive (by default the directoryarchive/) - this is a safe option and will leave you in a consistent state without deleting anything.delete: in addition to marking the packet as an orphan, also delete the files from your archive.
Later, we will add a "repair" option to try and fix broken packets.
The validation interacts with the option
core.require_complete_tree; if this option is TRUE, then a
packet is only valid if all its (recursive) dependencies are also
valid, so the action will apply to packets that have also had
their upstream dependencies invalidated. This validation will
happen even if the query implied by ... does not include these
packets if a complete tree is required.
The validation will also interact with core.use_file_store once
repair is supported, as this becomes trivial.
Examples
# Start with an archive containing 4 simple packets
path <- orderly_example()
#> ✔ Created orderly root at '/tmp/RtmpczjPxW/orderly_ex_1ecd4b312487'
ids <- vapply(1:4, function(i) orderly_run("data", root = path), "")
#> ℹ Starting packet 'data' `20251027-152744-7ebe6ee9` at 2025-10-27 15:27:44.499634
#> > orderly_description(
#> + display = "A demo data set")
#> > x <- jitter(1:30)
#> > y <- 0.4 * x + 5 + rnorm(length(x), sd = 2)
#> > d <- data.frame(x, y)
#> > orderly_artefact("data.rds", description = "A synthetic dataset")
#> > saveRDS(d, "data.rds")
#> ✔ Finished running data.R
#> ℹ Finished 20251027-152744-7ebe6ee9 at 2025-10-27 15:27:44.526151 (0.02651787 secs)
#> ℹ Starting packet 'data' `20251027-152744-8bf1971c` at 2025-10-27 15:27:44.551215
#> > orderly_description(
#> + display = "A demo data set")
#> > x <- jitter(1:30)
#> > y <- 0.4 * x + 5 + rnorm(length(x), sd = 2)
#> > d <- data.frame(x, y)
#> > orderly_artefact("data.rds", description = "A synthetic dataset")
#> > saveRDS(d, "data.rds")
#> ✔ Finished running data.R
#> ℹ Finished 20251027-152744-8bf1971c at 2025-10-27 15:27:44.576951 (0.02573633 secs)
#> ℹ Starting packet 'data' `20251027-152744-995fd668` at 2025-10-27 15:27:44.617694
#> > orderly_description(
#> + display = "A demo data set")
#> > x <- jitter(1:30)
#> > y <- 0.4 * x + 5 + rnorm(length(x), sd = 2)
#> > d <- data.frame(x, y)
#> > orderly_artefact("data.rds", description = "A synthetic dataset")
#> > saveRDS(d, "data.rds")
#> ✔ Finished running data.R
#> ℹ Finished 20251027-152744-995fd668 at 2025-10-27 15:27:44.644202 (0.02650809 secs)
#> ℹ Starting packet 'data' `20251027-152744-aa9f8cb9` at 2025-10-27 15:27:44.670934
#> > orderly_description(
#> + display = "A demo data set")
#> > x <- jitter(1:30)
#> > y <- 0.4 * x + 5 + rnorm(length(x), sd = 2)
#> > d <- data.frame(x, y)
#> > orderly_artefact("data.rds", description = "A synthetic dataset")
#> > saveRDS(d, "data.rds")
#> ✔ Finished running data.R
#> ℹ Finished 20251027-152744-aa9f8cb9 at 2025-10-27 15:27:44.696535 (0.02560139 secs)
# Suppose someone corrupts a packet by deleting a file:
fs::file_delete(file.path(path, "archive", "data", ids[[3]], "data.rds"))
# We can check all packets, and report on validity
orderly_validate_archive(root = path)
#> ✔ 20251027-152744-7ebe6ee9 (data) is valid
#> ✔ 20251027-152744-8bf1971c (data) is valid
#> ✖ 20251027-152744-995fd668 (data) is invalid due to its files
#> ✔ 20251027-152744-aa9f8cb9 (data) is valid
# Alternatively, we can take action and orphan the invalid packet:
orderly_validate_archive(action = "orphan", root = path)
#> ✔ 20251027-152744-7ebe6ee9 (data) is valid
#> ✔ 20251027-152744-8bf1971c (data) is valid
#> ✖ 20251027-152744-995fd668 (data) is invalid due to its files
#> ✔ 20251027-152744-aa9f8cb9 (data) is valid
# At which point the validation will not find this packet anymore
orderly_validate_archive(root = path)
#> ✔ 20251027-152744-7ebe6ee9 (data) is valid
#> ✔ 20251027-152744-8bf1971c (data) is valid
#> ✔ 20251027-152744-aa9f8cb9 (data) is valid
# The orphaned packet will no longer be found in most operations:
orderly_search(root = path)
#> [1] "20251027-152744-7ebe6ee9" "20251027-152744-8bf1971c"
#> [3] "20251027-152744-aa9f8cb9"
