diff --git a/R/evaluate.R b/R/evaluate.R index 4444c63..baf4253 100644 --- a/R/evaluate.R +++ b/R/evaluate.R @@ -152,7 +152,7 @@ evaluate <- function(input, ), eval_continue = function() TRUE, eval_stop = function() FALSE, - eval_error = function(cnd) {signalCondition(cnd); stop(cnd)} + eval_error = signal_error ) watcher$check_devices() @@ -167,6 +167,14 @@ evaluate <- function(input, watcher$get() } +signal_error <- function(cnd) { + signalCondition(cnd) + if (has_rlang) { + cnd <- rlang::cnd_entrace(cnd) + } + stop(cnd) +} + check_stop_on_error <- function(x) { if (is.numeric(x) && length(x) == 1 && !is.na(x)) { if (x == 0L) { diff --git a/R/zzz.R b/R/zzz.R index 0b3778a..517ac0b 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -3,6 +3,8 @@ evaluate_default_output_handler <- NULL # used by knitr, as above, but also for value handler default_output_handler <- NULL +has_rlang <- FALSE + .onLoad <- function(...) { evaluate_default_output_handler <<- new_output_handler() default_output_handler <<- new_output_handler() @@ -10,4 +12,6 @@ default_output_handler <- NULL default_output_handler$value <<- function(x) { render(x, visible = TRUE, envir = parent.frame()) } + + has_rlang <<- requireNamespace("rlang", quietly = TRUE) }