Skip to contents

Factory function to create an RCodeRunner instance for safe R code execution.

Usage

r_code_runner(
  timeout = 30,
  max_output_chars = 100000L,
  allowed_packages = c("base", "stats", "utils", "methods"),
  prelude = character()
)

Arguments

timeout

Numeric. Maximum execution time in seconds. Default 30.

max_output_chars

Integer. Maximum characters for stdout/stderr. Output exceeding this limit is truncated. Default 100000 (100KB).

allowed_packages

Character vector. Packages that may be loaded. This is defense-in-depth only; not a security boundary.

Default: c("base", "stats", "utils", "methods").

prelude

Character vector. R code to run before user code. Useful for setting options or loading common utilities.

Value

An RCodeRunner R6 object

Examples

if (FALSE) { # \dontrun{
runner <- r_code_runner(timeout = 10)
result <- runner$execute("sqrt(16)")
result$result
# [1] 4
} # }