# Use development build when interactive *and* explicitly enabled via env var.
dev_mode <- (Sys.getenv("DEV_VIGNETTES", "false") == "true")
if (dev_mode && requireNamespace("pkgload", quietly = TRUE)) {
cli::cli_inform("loading with {.pkg pkgload}")
pkgload::load_all()
} else {
# fall back to the installed package (the path CRAN, CI, and pkgdown take)
cli::cli_inform("loading with {.pkg library}")
library(stamp)
}## loading with library
This vignette shows how stamp captures lineage (parents → children), how to detect staleness, and how to plan & rebuild downstream artifacts in level order.
You’ll use:
st_children(), st_lineage()st_is_stale()st_plan_rebuild() (returns a plan
data.frame)st_register_builder(),
st_clear_builders(), st_rebuild()Strict vs. Propagate Strict checks actual mismatch vs the parents’ current latest versions. Propagate simulates change pushing downstream (A changes ⇒ schedule B ⇒ schedule C, etc.).
A few implementation notes that clarify behavior used by the examples below:
parents.json file inside a
version snapshot) are the authoritative record for lineage when present.
They are captured at commit time and are used for reproducible,
recursive lineage walking.parents field in the sidecar
metadata written next to the artifact file) are a lightweight
convenience that let you inspect first-level lineage before a snapshot
is committed. st_lineage() falls back to sidecar parents
only for the immediate parent level when no snapshot is available;
recursive walking beyond level 1 requires snapshot-backed parents.This design keeps interactive workflows fast (sidecars are quick) while preserving reproducible history once snapshots are written.
st_opts_reset()
st_opts(
versioning = "content",
code_hash = TRUE,
store_file_hash = TRUE,
verify_on_load = TRUE,
meta_format = "both"
)## ✔ stamp options updated
## versioning = "content", code_hash = "TRUE", store_file_hash = "TRUE",
## verify_on_load = "TRUE", meta_format = "both"
## ℹ Rebasing default alias to new folder.
## Existing: /tmp/RtmpCXgvOI/stamp-hashing-b56711b2d8/.stamp
## Requested: /tmp/RtmpCXgvOI/stamp-lineage-b56201a4497/.stamp
## ✔ stamp initialized
## alias: default
## root: /tmp/RtmpCXgvOI/stamp-lineage-b56201a4497
## state: /tmp/RtmpCXgvOI/stamp-lineage-b56201a4497/.stamp
# A
pA <- fs::path(root, "A.qs")
xA <- data.frame(a = 1:3)
st_save(xA, pA, code = function(z) z, alias = NULL)## ✔ Saved [qs2] → '/tmp/RtmpCXgvOI/stamp-lineage-b56201a4497/A.qs' @ version
## 2d803ad64c4fc07d
# B depends on A
pB <- fs::path(root, "B.qs")
xB <- transform(xA, b = a * 2)
st_save(
xB,
pB,
code = function(z) z,
parents = list(list(path = pA, version_id = st_latest(pA, alias = NULL))),
alias = NULL
)## ✔ Saved [qs2] → '/tmp/RtmpCXgvOI/stamp-lineage-b56201a4497/B.qs' @ version
## 4c223d27885af2c8
# C depends on B
pC <- fs::path(root, "C.qs")
xC <- transform(xB, c = b + 1L)
st_save(
xC,
pC,
code = function(z) z,
parents = list(list(path = pB, version_id = st_latest(pB, alias = NULL))),
alias = NULL
)## ✔ Saved [qs2] → '/tmp/RtmpCXgvOI/stamp-lineage-b56201a4497/C.qs' @ version
## 880aa9124abab4c4
Note: after these saves each artifact has a sidecar (in
stmeta/ next to the artifact) and snapshots in its own
versions/ directory (per-artifact storage, not
centralized).
## child_path child_version
## 1 /tmp/RtmpCXgvOI/stamp-lineage-b56201a4497/B.qs 4c223d27885af2c8
## parent_path parent_version level
## 1 /tmp/RtmpCXgvOI/stamp-lineage-b56201a4497/A.qs 2d803ad64c4fc07d 1
## level child_path child_version
## 1 1 /tmp/RtmpCXgvOI/stamp-lineage-b56201a4497/C.qs 880aa9124abab4c4
## 2 2 /tmp/RtmpCXgvOI/stamp-lineage-b56201a4497/B.qs 4c223d27885af2c8
## parent_path parent_version
## 1 /tmp/RtmpCXgvOI/stamp-lineage-b56201a4497/B.qs 4c223d27885af2c8
## 2 /tmp/RtmpCXgvOI/stamp-lineage-b56201a4497/A.qs 2d803ad64c4fc07d
# Change A → new version
xA2 <- transform(xA, a = a + 10L)
st_save(xA2, pA, code = function(z) z, alias = NULL)## ✔ Saved [qs2] → '/tmp/RtmpCXgvOI/stamp-lineage-b56201a4497/A.qs' @ version
## 7b2ff2a28d2832c8
## [1] TRUE
## [1] FALSE
Two strategies:
# Strict: only B right now
plan_strict <- st_plan_rebuild(pA, depth = Inf, mode = "strict")
plan_strict## level path reason
## 1 1 /tmp/RtmpCXgvOI/stamp-lineage-b56201a4497/B.qs parent_changed
## latest_version_before
## 1 4c223d27885af2c8
# Propagate: includes B (level 1) and C (level 2)
plan <- st_plan_rebuild(pA, depth = Inf, mode = "propagate")
plan## level path reason
## 1 1 /tmp/RtmpCXgvOI/stamp-lineage-b56201a4497/B.qs upstream_changed
## 2 2 /tmp/RtmpCXgvOI/stamp-lineage-b56201a4497/C.qs upstream_changed
## latest_version_before
## 1 4c223d27885af2c8
## 2 880aa9124abab4c4
Builders are tiny functions that produce an artifact
from its parents. They receive (path, parents) and return a
list with at least x = <object>.
# Register a builder for B: rebuild from A's committed version
st_register_builder(pB, function(path, parents) {
# parents is list(list(path=..., version_id=...))
A <- st_load_version(parents[[1]]$path, parents[[1]]$version_id, alias = NULL)
list(
x = transform(A, b = a * 2),
code = function(z) z,
code_label = "B <- A * 2"
)
})## ✔ Registered builder for /tmp/RtmpCXgvOI/stamp-lineage-b56201a4497/B.qs
## (default)
# Register a builder for C: rebuild from B's committed version
st_register_builder(pC, function(path, parents) {
B <- st_load_version(parents[[1]]$path, parents[[1]]$version_id, alias = NULL)
list(
x = transform(B, c = b + 1L),
code = function(z) z,
code_label = "C <- B + 1"
)
})## ✔ Registered builder for /tmp/RtmpCXgvOI/stamp-lineage-b56201a4497/C.qs
## (default)
# Dry run first (uses registered builders found by st_rebuild when rebuild_fun is NULL)
st_rebuild(plan, dry_run = TRUE)## ✔ Rebuild level 1: 1 artifact
## • /tmp/RtmpCXgvOI/stamp-lineage-b56201a4497/B.qs (upstream_changed)
## DRY RUN
## ✔ Rebuild level 2: 1 artifact
## • /tmp/RtmpCXgvOI/stamp-lineage-b56201a4497/C.qs (upstream_changed)
## DRY RUN
## ✔ Rebuild summary
## dry_run 2
## ✔ Rebuild level 1: 1 artifact
## • /tmp/RtmpCXgvOI/stamp-lineage-b56201a4497/B.qs (upstream_changed)
## ✔ Loaded ← /tmp/RtmpCXgvOI/stamp-lineage-b56201a4497/A.qs @ 7b2ff2a28d2832c8
## [qs2]
## ✔ Saved [qs2] → '/tmp/RtmpCXgvOI/stamp-lineage-b56201a4497/B.qs' @ version
## 42a7e7b805fa3420
## OK @ version 42a7e7b805fa3420
## ✔ Rebuild level 2: 1 artifact
## • /tmp/RtmpCXgvOI/stamp-lineage-b56201a4497/C.qs (upstream_changed)
## ✔ Loaded ← /tmp/RtmpCXgvOI/stamp-lineage-b56201a4497/B.qs @ 42a7e7b805fa3420
## [qs2]
## ✔ Saved [qs2] → '/tmp/RtmpCXgvOI/stamp-lineage-b56201a4497/C.qs' @ version
## f29085865d01ab65
## OK @ version f29085865d01ab65
## ✔ Rebuild summary
## built 2
## level path reason status
## 1 1 /tmp/RtmpCXgvOI/stamp-lineage-b56201a4497/B.qs upstream_changed built
## 2 2 /tmp/RtmpCXgvOI/stamp-lineage-b56201a4497/C.qs upstream_changed built
## version_id msg
## 1 42a7e7b805fa3420
## 2 f29085865d01ab65
After rebuilding B, C becomes strictly stale if B changes again later. You can re-plan from B to keep propagating:
## [1] FALSE
## [1] FALSE
## level path reason
## 1 1 /tmp/RtmpCXgvOI/stamp-lineage-b56201a4497/C.qs upstream_changed
## latest_version_before
## 1 f29085865d01ab65
vroot <- fs::path_dir(st_info(pA, alias = NULL)$sidecar$path)
vroot <- fs::path(vroot, "versions")
if (fs::dir_exists(vroot)) {
fs::dir_tree(vroot, recurse = TRUE, all = TRUE)
}Tip: st_info(path) summarizes sidecar,
catalog status, and the latest snapshot dir, plus parsed
parents.json from the committed snapshot (if present).
## $sidecar
## $sidecar$path
## [1] "/tmp/RtmpCXgvOI/stamp-lineage-b56201a4497/C.qs"
##
## $sidecar$format
## [1] "qs2"
##
## $sidecar$created_at
## [1] "2026-12-04T20:09:28.224994Z"
##
## $sidecar$size_bytes
## [1] 233
##
## $sidecar$content_hash
## [1] "650880ed8fce088d"
##
## $sidecar$code_hash
## [1] "488e8fa49c740261"
##
## $sidecar$file_hash
## [1] "f40f3549dd724726"
##
## $sidecar$code_label
## [1] "C <- B + 1"
##
## $sidecar$parents
## path version_id
## 1 /tmp/RtmpCXgvOI/stamp-lineage-b56201a4497/B.qs 42a7e7b805fa3420
##
## $sidecar$attrs
## list()
##
##
## $catalog
## $catalog$latest_version_id
## [1] "f29085865d01ab65"
##
## $catalog$n_versions
## [1] 2
##
##
## $snapshot_dir
## /tmp/RtmpCXgvOI/stamp-lineage-b56201a4497/C.qs/versions/f29085865d01ab65
##
## $parents
## $parents[[1]]
## $parents[[1]]$path
## [1] "/tmp/RtmpCXgvOI/stamp-lineage-b56201a4497/B.qs"
##
## $parents[[1]]$version_id
## [1] "42a7e7b805fa3420"