build_context() creates a compact, static context artifact for a named
function or method before a concrete call has been captured. It reuses
explain_function() and adds one hop of caller/callee context, unresolved
references, source files when available, and validation suggestions.
Usage
build_context(graph, entry, task = NULL, format = c("md", "json"), depth = 1L)Arguments
- graph
A
insider_graphfrombuild_graph(), or a target (source directory / installed package name) to build one from.- entry
Exact node name to use as the context entry point.
- task
Optional task label to include verbatim in the rendered context.
- format
Output format:
"md"for markdown or"json"for JSON.- depth
Call-path depth. Only
1Lis supported in this release.
Value
An insider_context object with fields format, text, and data.
Printing the object writes text directly to the console.
Examples
# \donttest{
build_context("stats", entry = "sd", task = "understand variance calls")
#> # insideR agent context
#>
#> Entry: sd (function, stats namespace (no line references), exported)
#> Task: understand variance calls
#>
#> ## Documentation
#> Title: Standard Deviation
#> Description: This function computes the standard deviation of the values in x . If na.rm is TRUE then missing values are removed before computation proceeds.
#>
#> ## Files
#> not applicable - installed mode has no source file references
#>
#> ## Call path (one hop)
#> Callers: bw.SJ, bw.nrd0
#> Callees (internal): var
#> Callees (external): as.double (base), if (base), is.factor (base), is.vector (base), sqrt (base), || (base)
#>
#> ## Method family
#> not identified as an S3 method
#>
#> ## Risk notes
#> - none identified
#>
#> ## Unresolved references
#> - none
#>
#> ## Validation
#> - `Re-run insider::explain_function("stats", "sd") after any edit and diff the callees/risk notes.`
#> - `Run R CMD check on the target package source tree.`
build_context("stats", entry = "sd", format = "json")
#> {
#> "schema_version": "1.0",
#> "entry": {
#> "name": "sd",
#> "kind": "function",
#> "location": "stats namespace (no line references)",
#> "exported": true
#> },
#> "task": null,
#> "documentation": {
#> "title": "Standard Deviation",
#> "description": "This function computes the standard deviation of the values in x . If na.rm is TRUE then missing values are removed before computation proceeds."
#> },
#> "files": [],
#> "files_note": "not applicable - installed mode has no source file references",
#> "call_path": {
#> "depth": 1,
#> "callers": ["bw.SJ", "bw.nrd0"],
#> "callees_internal": "var",
#> "callees_external": [
#> {
#> "callee": "as.double",
#> "package": "base"
#> },
#> {
#> "callee": "if",
#> "package": "base"
#> },
#> {
#> "callee": "is.factor",
#> "package": "base"
#> },
#> {
#> "callee": "is.vector",
#> "package": "base"
#> },
#> {
#> "callee": "sqrt",
#> "package": "base"
#> },
#> {
#> "callee": "||",
#> "package": "base"
#> }
#> ]
#> },
#> "method_family": null,
#> "risk_notes": "none identified",
#> "unresolved": [],
#> "validation_commands": ["Re-run insider::explain_function(\"stats\", \"sd\") after any edit and diff the callees/risk notes.", "Run R CMD check on the target package source tree."]
#> }
# }