From 623e9da9760dffb115915612e7133f8cf19ccd4d Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Sun, 16 Jun 2024 17:59:45 +0100 Subject: [PATCH 1/2] Eliminate enclose argument This eliminates one argument we need to thread through multiple function calls by creating a new environment with appropriate parent. (I doubt anyone actually uses this argument but it should be a safe transformation) --- R/eval.R | 14 ++++++-------- R/utils.R | 1 + 2 files changed, 7 insertions(+), 8 deletions(-) create mode 100644 R/utils.R diff --git a/R/eval.R b/R/eval.R index 8d2b84f..a3556f4 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) { @@ -103,7 +103,6 @@ evaluate <- function(input, expr, parsed$src[[i]], envir = envir, - enclos = enclos, debug = debug, last = i == length(out), use_try = stop_on_error != 2L, @@ -132,7 +131,6 @@ evaluate <- function(input, evaluate_call <- function(call, src = NULL, envir = parent.frame(), - enclos = NULL, debug = FALSE, last = FALSE, use_try = FALSE, @@ -254,7 +252,7 @@ evaluate_call <- function(call, 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 @@ -286,9 +284,9 @@ evaluate_call <- function(call, 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)) { @@ -297,7 +295,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 new file mode 100644 index 0000000..9c70ac7 --- /dev/null +++ b/R/utils.R @@ -0,0 +1 @@ +`%||%` <- function(a, b) if (is.null(a)) b else a From 6aad272a2c11fbec1a7b030a94278627d2b23f5b Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Tue, 18 Jun 2024 17:04:14 +0100 Subject: [PATCH 2/2] WS --- R/eval.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/eval.R b/R/eval.R index 45003e9..8f82290 100644 --- a/R/eval.R +++ b/R/eval.R @@ -127,7 +127,7 @@ evaluate <- function(input, evaluate_top_level_expression <- function(exprs, src = NULL, envir = parent.frame(), - debug = FALSE, + debug = FALSE, last = FALSE, use_try = FALSE, keep_warning = TRUE,