diff --git a/R/eval.R b/R/eval.R index fe994ea..8be1f5c 100644 --- a/R/eval.R +++ b/R/eval.R @@ -64,8 +64,8 @@ evaluate <- function(input, return(list(source, err)) } - if (is.null(enclos)) { - enclos <- if (is.list(envir) || is.pairlist(envir)) parent.frame() else baseenv() + if (is.list(envir)) { + envir <- list2env(envir, parent = enclos %||% parent.frame()) } if (new_device) { @@ -99,7 +99,6 @@ evaluate <- function(input, exprs = parsed$expr[[i]], src = parsed$src[[i]], envir = envir, - enclos = enclos, debug = debug, last = i == length(out), use_try = stop_on_error != 2L, @@ -128,7 +127,6 @@ evaluate <- function(input, evaluate_top_level_expression <- function(exprs, src = NULL, envir = parent.frame(), - enclos = NULL, debug = FALSE, last = FALSE, use_try = FALSE, @@ -242,7 +240,7 @@ evaluate_top_level_expression <- function(exprs, srcindex <- length(output) time <- timing_fn(handle( ev <- withCallingHandlers( - withVisible(eval_with_user_handlers(expr, envir, enclos, user_handlers)), + withVisible(eval_with_user_handlers(expr, envir, user_handlers)), warning = wHandler, error = eHandler, message = mHandler @@ -274,9 +272,9 @@ evaluate_top_level_expression <- function(exprs, output } -eval_with_user_handlers <- function(expr, envir, enclos, calling_handlers) { +eval_with_user_handlers <- function(expr, envir, calling_handlers) { if (!length(calling_handlers)) { - return(eval(expr, envir, enclos)) + return(eval(expr, envir)) } if (!is.list(calling_handlers)) { @@ -285,7 +283,7 @@ eval_with_user_handlers <- function(expr, envir, enclos, calling_handlers) { call <- as.call(c( quote(withCallingHandlers), - quote(eval(expr, envir, enclos)), + quote(eval(expr, envir)), calling_handlers )) diff --git a/R/utils.R b/R/utils.R index c46dda2..1df0c3e 100644 --- a/R/utils.R +++ b/R/utils.R @@ -2,3 +2,5 @@ defer <- function(expr, frame = parent.frame(), after = FALSE) { thunk <- as.call(list(function() expr)) do.call(on.exit, list(thunk, TRUE, after), envir = frame) } + +`%||%` <- function(a, b) if (is.null(a)) b else a