eval_safe | R Documentation |
Evaluates an expression in a temporary fork and returns the value without any
side effects on the main R session. For eval_safe()
the expression is wrapped
in additional R code to handle errors and graphics.
eval_safe(
expr,
tmp = tempfile("fork"),
std_out = stdout(),
std_err = stderr(),
timeout = 0,
priority = NULL,
uid = NULL,
gid = NULL,
rlimits = NULL,
profile = NULL,
device = pdf
)
eval_fork(
expr,
tmp = tempfile("fork"),
std_out = stdout(),
std_err = stderr(),
timeout = 0
)
expr |
expression to evaluate |
tmp |
the value of |
std_out |
if and where to direct child process |
std_err |
if and where to direct child process |
timeout |
maximum time in seconds to allow for call to return |
priority |
(integer) priority of the child process. High value is low priority. |
uid |
evaluate as given user (uid or name). See |
gid |
evaluate as given group (gid or name). See |
rlimits |
named vector/list with rlimit values, for example: |
profile |
AppArmor profile, see |
device |
graphics device to use in the fork, see |
Some programs such as Java
are not fork-safe and cannot be called from within a
forked process if they have already been loaded in the main process. On MacOS any
software calling CoreFoundation
functionality might crash within the fork. This
includes libcurl
which has been built on OSX against native SecureTransport rather
than OpenSSL for https connections. The same limitations hold for e.g. parallel::mcparallel()
.
# works like regular eval:
eval_safe(rnorm(5))
# Exceptions get propagated
test <- function() { doesnotexit() }
tryCatch(eval_safe(test()), error = function(e){
cat("oh no!", e$message, "\n")
})
# Honor interrupt and timeout, even inside C evaluations
try(eval_safe(svd(matrix(rnorm(1e8), 1e4)), timeout = 2))
# Capture output
outcon <- rawConnection(raw(0), "r+")
eval_safe(print(sessionInfo()), std_out = outcon)
cat(rawToChar(rawConnectionValue(outcon)))
close(outcon)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.