R/ai_tool_run_r_command.R

Defines functions run_r_command

#' @importFrom utils capture.output
run_r_command <- function(args) {
  if (!validate_command_args(ai_tool_run_r_command, args)) {
    stop("Invalid arguments for RunRCommand")
  }
  output <- paste(
    capture.output(eval(parse(text = args$command), envir = new.env(parent = .GlobalEnv))),
    collapse = "\n"
  )
  list(output = output)
}

ai_tool_run_r_command <- list(
  name = "RunRCommand",
  parameters = list(
    list(name = "command")
  ),
  display_title = "Run R Command",
  would_like_to = "Run the R command: `{command}`",
  is_currently = "Running the R command: `{command}`",
  has_already = "Ran the R command: `{command}`",
  readonly = FALSE,
  execute = run_r_command
)

Try the myownrobs package in your browser

Any scripts or data that you put into this service are public.

myownrobs documentation built on Nov. 5, 2025, 5:52 p.m.