diff --git a/NEWS b/NEWS index bd456fe2..e1d100f7 100644 --- a/NEWS +++ b/NEWS @@ -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 ------------------------------------------------------------------------------ diff --git a/R/eval.r b/R/eval.r index 0d79911a..7a3e2d3d 100644 --- a/R/eval.r +++ b/R/eval.r @@ -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) { diff --git a/inst/tests/test-evaluate.r b/inst/tests/test-evaluate.r index f334c437..309db52b 100644 --- a/inst/tests/test-evaluate.r +++ b/inst/tests/test-evaluate.r @@ -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")