Skip to content

Commit

Permalink
if the env var R_EVALUATE_BYPASS_MESSAGES is set to true, messages …
Browse files Browse the repository at this point in the history
…will not be handled by evaluate()

yihui/yihui.org#1458 (reply in thread)
  • Loading branch information
yihui committed Oct 10, 2023
1 parent 7d86aef commit ee0fa82
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: evaluate
Type: Package
Title: Parsing and Evaluation Tools that Provide More Details than the Default
Version: 0.22.2
Version: 0.22.3
Authors@R: c(
person("Hadley", "Wickham", role = "aut"),
person("Yihui", "Xie", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0003-0645-5666")),
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Version 0.23

- Prevent existing plots from leaking into `evaluate()` results (thanks, @dmurdoch, yihui/knitr#2297).

- If the environment variable `R_EVALUATE_BYPASS_MESSAGES` is set to true, the arguments `keep_message` and `keep_warning` of `evaluate()` will be set to `NA`, regardless of user input, which means messages and warnings will not be captured by `evaluate()`. This provides a possibility to force logging messages and warnings (thanks, @slodge, yihui/yihui.org#1458).

Version 0.22
================================================================================

Expand Down
9 changes: 8 additions & 1 deletion R/eval.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
#' the code into the command line.
#' @param keep_warning,keep_message whether to record warnings and messages; if
#' `FALSE`, messages will be suppressed; if `NA`, they will not be captured
#' (normally they will be sent to the console).
#' (normally they will be sent to the console). Note that if the environment
#' variable `R_EVALUATE_BYPASS_MESSAGES` is set to true, these arguments will
#' always be set to `NA`, meaning that messages will not be captured by this
#' function.
#' @param log_echo,log_warning If `TRUE`, will immediately log code and
#' warnings (respectively) to `stderr`.
#' @param new_device if `TRUE`, will open a new graphics device and
Expand Down Expand Up @@ -83,6 +86,10 @@ evaluate <- function(input,
# clean up the last_plot object after an evaluate() call (cf yihui/knitr#722)
on.exit(assign("last_plot", NULL, envir = environment(plot_snapshot)), add = TRUE)

# if this env var is set to true, always bypass messages
if (tolower(Sys.getenv('R_EVALUATE_BYPASS_MESSAGES')) == 'true')
keep_message = keep_warning = NA

out <- vector("list", nrow(parsed))
for (i in seq_along(out)) {
# if dev.off() was called, make sure to restore device to the one opened by
Expand Down
5 changes: 4 additions & 1 deletion man/evaluate.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ee0fa82

Please sign in to comment.