Skip to contents

Generate R code containing the complete program artifact and its restoration call. This preserves nested graphs and exact schemas without hand-rendering module fields.

Usage

export_module_code(
  module,
  name = "mod",
  include_demos = TRUE,
  file = NULL,
  registry = list(),
  trusted = FALSE
)

Arguments

module

A DSPrrr module to export.

name

Character; variable name for the module in generated code. Default is "mod".

include_demos

Logical; whether to include demonstration examples in the generated code. Default is TRUE.

file

Optional file path to write the code to. If NULL (default), returns the code as a character string. Existing files are atomically replaced only after the staged output parses successfully.

registry

Named runtime registry; see program-artifact.

trusted

Whether trusted runtime values may be embedded. Standalone code export rejects registry and embedded runtime references.

Value

If file is NULL, returns the R code as a character string. If file is specified, writes it atomically and returns the code invisibly.

Examples

if (FALSE) {
mod <- module(signature("text -> sentiment"), type = "predict")
mod$optimize_grid(data, metric, parameters = list(temperature = c(0.3, 1.0)))

# Get code as string
code <- export_module_code(mod)
cat(code)

# Write to file
export_module_code(mod, file = "optimized_module.R")
}