Reopens a snapshot that already exists in a DuckDB file. This is the durable
research workflow counterpart to ledgr_snapshot_from_df(): create and seal a
snapshot once, then load it by path and snapshot id in later R sessions.
Arguments
- db_path
Path to an existing DuckDB file.
- snapshot_id
Snapshot id to load. The snapshot must exist and be
SEALED.- verify
Logical scalar. If
TRUE, recompute the complete current-rule snapshot hash and compare it with the stored hash before returning, even when this process already verified the same snapshot tuple. IfFALSE, opening is metadata-only; the first snapshot-dependent use verifies cold.
Details
ledgr_snapshot_open() never creates or overwrites snapshots. It only returns
a handle to an existing sealed snapshot. Closing the returned object releases
its DuckDB connection; it does not delete the database file.
Articles
Durable experiment stores:
vignette("experiment-store", package = "ledgr")
system.file("doc", "experiment-store.html", package = "ledgr")
Examples
db_path <- tempfile(fileext = ".duckdb")
bars <- data.frame(
ts_utc = as.POSIXct("2020-01-01", tz = "UTC") + 86400 * 0:2,
instrument_id = "AAA",
open = c(100, 101, 102),
high = c(101, 102, 103),
low = c(99, 100, 101),
close = c(100, 101, 102),
volume = 1000
)
snapshot <- ledgr_snapshot_from_df(bars, db_path = db_path)
snapshot_id <- snapshot$snapshot_id
ledgr_snapshot_close(snapshot)
snapshot <- ledgr_snapshot_open(db_path, snapshot_id, verify = TRUE)
ledgr_snapshot_info(snapshot)
#> # A tibble: 1 × 14
#> snapshot_id status created_at_utc sealed_at_utc snapshot_hash
#> <chr> <chr> <chr> <chr> <chr>
#> 1 snapshot_20261027_174441_9e… SEALED 2026-10-27T17… 2026-10-27T1… 0152b9a0e0b2…
#> # ℹ 9 more variables: hash_rule_version <int>, verified_in_process <lgl>,
#> # bar_count <int>, instrument_count <int>, off_session_bar_count <int>,
#> # start_date <chr>, end_date <chr>, meta_json <chr>, error_msg <chr>
ledgr_snapshot_close(snapshot)