Learn R Programming

sys (version 3.4.3)

exec_r: Execute R from R

Description

Convenience wrappers for exec_wait and exec_internal that shell out to R itself: R.home("bin/R").

Usage

r_wait(
  args = "--vanilla",
  std_out = stdout(),
  std_err = stderr(),
  std_in = NULL
)

r_internal(args = "--vanilla", std_in = NULL, error = TRUE)

r_background(args = "--vanilla", std_out = TRUE, std_err = TRUE, std_in = NULL)

Arguments

args

command line arguments for R

std_out

if and where to direct child process STDOUT. Must be one of TRUE, FALSE, filename, connection object or callback function. See section on Output Streams below for details.

std_err

if and where to direct child process STDERR. Must be one of TRUE, FALSE, filename, connection object or callback function. See section on Output Streams below for details.

std_in

a file to send to stdin, usually an R script (see examples).

error

automatically raise an error if the exit status is non-zero.

Details

This is a simple but robust way to invoke R commands in a separate process. Use the callr package if you need more sophisticated control over (multiple) R process jobs.

See Also

Other sys: exec

Examples

Run this code
# Hello world
r_wait("--version")

# Run some code
r_wait(c('--vanilla', '-q', '-e', 'sessionInfo()'))

# Run a script via stdin
tmp <- tempfile()
writeLines(c("x <- rnorm(100)", "mean(x)"), con = tmp)
r_wait(std_in = tmp)

Run the code above in your browser using DataLab