callr (version 1.0.0)

r_safe: Run an R child process in safe mode

Description

The following options are set up:

  • The library path is set to the current path.

  • Makes sure that at least one reasonable CRAN mirror is set up.

  • Some command line arguments are added to avoid saving .RData files, etc. See them above.

  • The system and user profile files are ignored.

  • Various environment variables are set: CYGWIN to avoid warnings about DOS-style paths, R_TESTS to avoid issues when callr is invoked from unit tests, R_BROWSER and R_PDFVIEWER to avoid starting a browser or a PDF viewer.

Usage

r_safe(func, args = list(), libpath = .libPaths(),
  repos = c(getOption("repos"), c(CRAN = "https://cran.rstudio.com")),
  cmdargs = c("--no-site-file", "--no-environ", "--slave", "--no-save",
  "--no-restore"), system_profile = FALSE, user_profile = FALSE,
  env = c(CYGWIN = "nodosfilewarning", R_TESTS = "", R_BROWSER = "false",
  R_PDFVIEWER = "false"), ...)

Arguments

func

Function object to call in the new R process. The function should be self-contained and only refer to other functions and use variables explicitly from other packages using the :: notation. The environment of the function is set to .GlobalEnv before passing it to the child process. Because of this, it is good practice to create an anonymous function and pass that to callr, instead of passing a function object from a (base or other) package. In particular

  r(.libPaths)

does not work, because it is defined in a special environment, but

  r(function() .libPaths())

works just fine.

args

Arguments to pass to the function. Must be a list. vector.

libpath

The library path.

repos

The ‘repos’ option. If NULL, then no repos option is set. This options is only used if user_profile or system_profile is set to FALSE, as it is set using the system or the user profile.

cmdargs

Command line arguments to pass to the R process. Note that c("-f", rscript) is appended to this, rscript is the name of the script file to run. This contains a call to the supplied function and some error handling code.

system_profile

Whether to use the system profile file.

user_profile

Whether to use the user's profile file.

env

Environment variables to set for the child process.

...

Additional arguments are passed to r.

See Also

Other callr functions: r_vanilla, r