From 389382f66cf6b82ff3495945ac0c596a5ddce8da Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Mon, 8 Jul 2024 17:05:37 +0200 Subject: [PATCH] Avoid using evaluate internals (#2353) In a few years, once this code is widespread in installed knitr, this will allow us to make some simplifications to evaluate --- R/output.R | 5 +++-- R/utils.R | 4 ++-- R/zzz.R | 2 ++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/R/output.R b/R/output.R index d93ee5e7be..82cbfe2f1d 100644 --- a/R/output.R +++ b/R/output.R @@ -733,8 +733,9 @@ knit_print.knit_asis_url = function(x, ...) x #' @rdname knit_print #' @export -normal_print = default_handlers$value -formals(normal_print) = alist(x = , ... = ) +normal_print = function(x, ...) { + if (isS4(x)) methods::show(x) else print(x) +} #' Mark an R object with a special class #' diff --git a/R/utils.R b/R/utils.R index 5d8cdfc353..1c7d2b48bd 100644 --- a/R/utils.R +++ b/R/utils.R @@ -857,8 +857,8 @@ current_input = function(dir = FALSE) { if (is_abs_path(input)) input else file.path(outwd, input) } -# import output handlers from evaluate -default_handlers = evaluate:::default_output_handler +# cache output handlers from evaluate; see .onLoad +default_handlers = NULL # change the value handler in evaluate default handlers knit_handlers = function(fun, options) { if (!is.function(fun)) fun = function(x, ...) { diff --git a/R/zzz.R b/R/zzz.R index 89ffdd107f..37ee15324c 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -1,3 +1,5 @@ .onLoad = function(lib, pkg) { register_vignette_engines(pkg) + + default_handlers <<- evaluate::new_output_handler() }