Statically extract one package function and its reachable internal helpers into a single R source file with package, source, and license provenance. The target function is not invoked. Loading its namespace may still run the package's standard namespace startup hooks.
Usage
extract_function(
package,
name,
output_file,
max_depth = 5L,
dispatch = c("candidates", "static"),
overwrite = FALSE
)Arguments
- package
A single installed package name.
- name
A single function name, exported or internal.
- output_file
Path to the R source file to write.
- max_depth
Maximum internal helper depth to extract.
- dispatch
How unresolved S3 dispatch should be handled.
"candidates"extracts package-internal candidate methods when possible;"static"keeps only statically resolved methods.- overwrite
Whether to overwrite an existing output file.
Examples
out <- tempfile(fileext = ".R")
extract_function("stats", "fivenum", out, overwrite = TRUE)
#>
#> ── insideR extract ─────────────────────────────────────────────────────────────
#> Entry function: `stats::fivenum`
#> Package: stats 4.6.1
#> License: Part of R 4.6.1
#> Source file written to /tmp/Rtmpvw2GbA/file180e3ac0485b.R
#> • Extracted function count: 1
#> • Extraction status: full
#> • Security scan: no risky calls detected