Skip to content

Commit

Permalink
respect options(warn=-1); fixes yihui/knitr#610
Browse files Browse the repository at this point in the history
  • Loading branch information
yihui committed Sep 25, 2013
1 parent 6ef58e2 commit 2caeebd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
5 changes: 5 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ BUG FIXES
* the empty plots produced by strwidth(), strheight(), and clip() are no
longer recorded

MAJOR CHANGES

* evaluate() no longer records warnings in case of options(warn = -1); see
yihui/knitr#610

Version 0.4.7
------------------------------------------------------------------------------

Expand Down
6 changes: 4 additions & 2 deletions R/eval.r
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,10 @@ evaluate_call <- function(call, src = NULL,

# Handlers for warnings, errors and messages
wHandler <- if (keep_warning) function(wn) {
handle_condition(wn)
output_handler$warning(wn)
if (getOption("warn") >= 0) {
handle_condition(wn)
output_handler$warning(wn)
}
invokeRestart("muffleWarning")
} else identity
eHandler <- if (use_try) function(e) {
Expand Down
5 changes: 5 additions & 0 deletions inst/tests/test-evaluate.r
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ test_that("errors during printing visible values are captured", {
stopifnot("error" %in% class(ev[[2]]))
})

test_that("options(warn = -1) suppresses warnings", {
ev <- evaluate("op = options(warn = -1); warning('hi'); options(op)")
expect_that(classes(ev), equals("source"))
})

op <- options(device = function(...) {
pdf(file = NULL)
dev.control("enable")
Expand Down

0 comments on commit 2caeebd

Please sign in to comment.