r {callr} | R Documentation |
Evaluate an expression in another R session
r(func, args = list(), libpath = .libPaths(), repos = getOption("repos"), stdout = NULL, stderr = NULL, error = c("error", "stack", "debugger"), cmdargs = "--slave", show = FALSE, callback = NULL, system_profile = TRUE, user_profile = TRUE, env = character())
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 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 |
stdout |
The name of the file the standard output of
the child R process will be written to.
If the child process runs with the |
stderr |
The name of the file the standard error of
the child R process will be written to.
In particular |
error |
What to do if the remote process throws an error. See details below. |
cmdargs |
Command line arguments to pass to the R process.
Note that |
show |
Logical, whether to show the standard output on the screen
while the child process is running. Note that this is independent
of the |
callback |
A function to call for each line of the standard
output from the child process. It works together with the |
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. |
Value of the evaluated expression.
callr
handles errors properly. If the child process throws an
error, then callr
throws an error with the same error message
in the parent process.
The ‘error’ expert option may be used to specify a different behavior on error. The following values are possible:
‘error’ is the default behavior: throw an error in the parent, with the same error message. In fact the same error object is thrown again.
‘stack’ also throws an error in the parent, but the error
is of a special kind, class callr_condition
, and it contains
both the original error object, and the call stack of the child,
as written out by dump.frames
.
‘debugger’ is similar to ‘stack’, but in addition
to returning the complete call stack, it also start up a debugger
in the child call stack, via debugger
.
Other callr functions: r_safe
,
r_vanilla
# Workspace is empty r(function() ls()) # library path is the same by default r(function() .libPaths()) .libPaths()