Unpack a package call into a self-contained, self-verifying replay script
Source:R/unpack_call.R
unpack_call.RdRuns the call once, captures its inputs and result, extracts the source of the executed function and its same-package helpers, and writes a replay project:
Arguments
- expr
An unevaluated function call, written as you would normally run it, e.g.
predict(fit, newdata = recent_data)orstats::fivenum(x). For S3 generics the dispatch argument is evaluated once to determine the method.- output_dir
Directory to create the replay project in.
- max_depth
Maximum depth to follow same-package internal helpers.
- overwrite
Overwrite an existing non-empty
output_dir?
Details
output_dir/
replay.R self-contained script: documented functions,
input loading, the reproducing call, and a
verification block
data/*.rds captured inputs and the original result
insider_manifest.rds machine-readable unpack metadataRunning source("replay.R") from output_dir re-executes the call using
the extracted functions and checks the result against the stored original
(and, when the package is installed, against a live package call). The
script header records provenance (package, version, source repository) and
the findings of a static security scan of the extracted code.
Examples
x <- c(1, 3, 5, 7, 100)
dir <- file.path(tempdir(), "fivenum_replay")
unpack_call(stats::fivenum(x), output_dir = dir, overwrite = TRUE)
#>
#> ── insideR unpack ──────────────────────────────────────────────────────────────
#> Call: `stats::fivenum(x)`
#> Replay project written to /tmp/RtmpJhnVG8/fivenum_replay
#> • Script: /tmp/RtmpJhnVG8/fivenum_replay/replay.R
#> • Extracted function: `fivenum()`
#> • Captured input: "x"
#> • Replay status: full
#> • Security scan: no risky calls detected
#> Run it with: `setwd("/tmp/RtmpJhnVG8/fivenum_replay"); source("replay.R")`