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 anyoutpackroot (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/RtmpczjPxW/orderly_ex_1ecd4c70ae00'
ids <- vapply(1:4, function(i) orderly_run("data", root = path), "")
#> ℹ Starting packet 'data' `20251027-152740-76cef395` at 2025-10-27 15:27:40.468581
#> > 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-152740-76cef395 at 2025-10-27 15:27:40.49488 (0.026299 secs)
#> ℹ Starting packet 'data' `20251027-152740-83de2287` at 2025-10-27 15:27:40.519463
#> > 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-152740-83de2287 at 2025-10-27 15:27:40.546028 (0.02656531 secs)
#> ℹ Starting packet 'data' `20251027-152740-91840da2` at 2025-10-27 15:27:40.57292
#> > 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-152740-91840da2 at 2025-10-27 15:27:40.599245 (0.0263257 secs)
#> ℹ Starting packet 'data' `20251027-152740-a3c30254` at 2025-10-27 15:27:40.644162
#> > 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-152740-a3c30254 at 2025-10-27 15:27:40.670596 (0.02643371 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)
#> ✔ 20251027-152740-76cef395 (data) is valid
#> ✔ 20251027-152740-83de2287 (data) is valid
#> ✖ 20251027-152740-91840da2 (data) is invalid due to its files
#> ✔ 20251027-152740-a3c30254 (data) is valid
# Prune our orphans:
orderly_prune_orphans(root = path)
#> ℹ Pruning 1 orphan packet
