export_module_code() writes R code that rebuilds a program: the complete
program artifact (see program_artifact()) followed by a call to
restore_module_config(). Nested programs and exact output schemas are
preserved.
Usage
export_module_code(
module,
name = "mod",
include_demos = TRUE,
file = NULL,
registry = list(),
trusted = FALSE
)Arguments
- module
A module or composed program.
- name
Variable name for the program in the generated code (default
"mod").- include_demos
Whether to include the demonstrations (default
TRUE).- file
Optional path. When given, the code is written there; an existing file is replaced only after the new code parses.
- registry, trusted
As in
program_artifact(). Standalone code cannot embed registry or trusted runtime references, so programs that need them are rejected; usesave_program()for those.
See also
Other optimization results:
apply_best_config(),
best_demos(),
best_params(),
config_diff(),
optimization_result(),
optimization_summary(),
top_trials()
Other persistence:
pin_module_config(),
pin_trace(),
pin_vitals_log(),
program-artifact,
restore_module_config()
Examples
mod <- module(signature("text -> sentiment"))
path <- tempfile(fileext = ".R")
export_module_code(mod, name = "sentiment_mod", file = path)
#> Module code written to /tmp/Rtmp4xxnp9/file1b1b738acbad.R
# Running the file rebuilds the program
source(path)
#> ✔ Restored program artifact
#> ℹ Root module: <PredictModule>
#> ℹ Artifact version: 6
sentiment_mod
#>
#> ── PredictModule ──
#>
#> ── Signature
#>
#> ── Signature ──
#>
#> ── Inputs
#> • text: "string" - Input: text
#>
#> ── Output
#> Type: "object(sentiment: string)"
#>
#> ── Instructions
#> Given the fields `text`, produce the fields `sentiment`.