Prune orphan packets from your metadata store. This function can
be used to remove references to packets that are no longer
reachable; this could have happened because you deleted a packet
manually from the archive and ran
orderly_validate_archive()
or because you removed a
location.
Arguments
- 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 anyoutpack
root (seeorderly_init()
for details).
Details
If an orphan packet is not used anywhere, then we can easily drop it - it's as if it never existed. If it is referenced by metadata that you know about from elsewhere but not locally, then that is a problem for the upstream location (and one that should not happen). If you have referenced it in a packet that you have run locally, the the metadata is not deleted.
We expose this function mostly for users who want to expunge permanently any reference to previously run packets. We hope that there should never need to really be a reason to run it.
Examples
# The same example as orderly_validate_archive; a corrupted
# archive due to the local deletion of a file
# Start with an archive containing 4 simple packets
path <- orderly_example()
#> ✔ Created orderly root at '/tmp/Rtmp5CJVz5/orderly_ex_1ea858505e44'
ids <- vapply(1:4, function(i) orderly_run("data", root = path), "")
#> ℹ Starting packet 'data' `20251009-084344-17b27c94` at 2025-10-09 08:43:44.097169
#> > 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 20251009-084344-17b27c94 at 2025-10-09 08:43:44.123423 (0.02625394 secs)
#> ℹ Starting packet 'data' `20251009-084344-24d44fef` at 2025-10-09 08:43:44.148321
#> > 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 20251009-084344-24d44fef at 2025-10-09 08:43:44.174618 (0.02629638 secs)
#> ℹ Starting packet 'data' `20251009-084344-3264952d` at 2025-10-09 08:43:44.20131
#> > 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 20251009-084344-3264952d at 2025-10-09 08:43:44.228023 (0.02671337 secs)
#> ℹ Starting packet 'data' `20251009-084344-443770f8` at 2025-10-09 08:43:44.270988
#> > 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 20251009-084344-443770f8 at 2025-10-09 08:43:44.297277 (0.02628899 secs)
fs::file_delete(file.path(path, "archive", "data", ids[[3]], "data.rds"))
# Validate the archive ands orphan corrupt packets:
orderly_validate_archive(action = "orphan", root = path)
#> ✔ 20251009-084344-17b27c94 (data) is valid
#> ✔ 20251009-084344-24d44fef (data) is valid
#> ✖ 20251009-084344-3264952d (data) is invalid due to its files
#> ✔ 20251009-084344-443770f8 (data) is valid
# Prune our orphans:
orderly_prune_orphans(root = path)
#> ℹ Pruning 1 orphan packet