From 14c96090102be7dfd48c7811f85895d1f848b0d1 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Thu, 20 Jun 2024 16:02:03 +0100 Subject: [PATCH] Restore object that knitr uses (#162) * Restore object that knitr uses * Re-document --- R/eval.R | 4 +++- R/zzz.R | 6 ++++++ man/evaluate.Rd | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 R/zzz.R diff --git a/R/eval.R b/R/eval.R index 7711afd..9c97a0b 100644 --- a/R/eval.R +++ b/R/eval.R @@ -47,12 +47,14 @@ evaluate <- function(input, log_echo = FALSE, log_warning = FALSE, new_device = TRUE, - output_handler = new_output_handler(), + output_handler = NULL, filename = NULL, include_timing = FALSE) { stop_on_error <- as.integer(stop_on_error) stopifnot(length(stop_on_error) == 1) + output_handler <- output_handler %||% default_output_handler + if (isTRUE(include_timing)) { warning("`evaluate(include_timing)` is deprecated") } diff --git a/R/zzz.R b/R/zzz.R new file mode 100644 index 0000000..ccc8811 --- /dev/null +++ b/R/zzz.R @@ -0,0 +1,6 @@ +# used by knitr to avoid overheard of calling new_output_handler() repeatedly +default_output_handler <- NULL + +.onLoad <- function(...) { + default_output_handler <<- new_output_handler() +} diff --git a/man/evaluate.Rd b/man/evaluate.Rd index 9093d1a..d76f7ba 100644 --- a/man/evaluate.Rd +++ b/man/evaluate.Rd @@ -15,7 +15,7 @@ evaluate( log_echo = FALSE, log_warning = FALSE, new_device = TRUE, - output_handler = new_output_handler(), + output_handler = NULL, filename = NULL, include_timing = FALSE )