library("RAppArmor")
#* Evaluate the result
#* @post /eval_res
function(func){
data <- cbind(rnorm(100),rnorm(100))
unix::eval_safe(nrow(data), profile="r-user")
}
所以
library("RAppArmor")
#* Evaluate the result
#* @post /eval_res
function(func){
data <- cbind(rnorm(100),rnorm(100))
unix::eval_safe(eval(parse(text=func)), profile="r-user")
}
eval.secure
只需将所有参数传递给unix::eval_safe
. eval.secure
不起作用的原因是因为eval_safe
期望在它的 中找到你的变量parent.frame()
,在这种情况下eval.secure
是一个空的函数体。
eval_safe
使用 parent.frame()
function (expr, tmp = tempfile("fork"), std_out = stdout(), std_err = stderr(),
timeout = 0, priority = NULL, uid = NULL, gid = NULL, rlimits = NULL,
profile = NULL, device = pdf)
{
orig_expr <- substitute(expr)
out <- eval_fork(expr = tryCatch({
if (length(priority))
setpriority(priority)
if (length(rlimits))
set_rlimits(rlimits)
if (length(gid))
setgid(gid)
if (length(uid))
setuid(uid)
if (length(profile))
aa_change_profile(profile)
if (length(device))
options(device = device)
graphics.off()
options(menu.graphics = FALSE)
------> serialize(withVisible(eval(orig_expr, parent.frame())),
NULL)
}, error = function(e) {
old_class <- attr(e, "class")
structure(e, class = c(old_class, "eval_fork_error"))
}, finally = substitute(graphics.off())), tmp = tmp, timeout = timeout,
std_out = std_out, std_err = std_err)
if (inherits(out, "eval_fork_error"))
base::stop(out)
res <- unserialize(out)
if (res$visible)
res$value
else invisible(res$value)
}
# parent.frame() in eval_safe when using eval.secure
function (...)
{
# nothing here
unix::eval_safe(...)
}
# parent.frame() when using eval_safe directly
function(func){
data <- cbind(rnorm(100),rnorm(100))
# Your stuff is here
unix::eval_safe(nrow(data), profile="r-user")
}