# NOT RUN {
#Only works on Unix
if(.Platform$OS.type == "unix"){
# 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)
}
# }
Run the code above in your browser using DataCamp Workspace