diff --git a/R/eval.R b/R/eval.R index 8d2b84f..0e599ce 100644 --- a/R/eval.R +++ b/R/eval.R @@ -69,10 +69,9 @@ evaluate <- function(input, } if (new_device) { - # Start new graphics device and clean up afterwards - if (identical(grDevices::pdf, getOption("device"))) { - dev.new(file = NULL) - } else dev.new() + # Ensure we have a graphics device available for recording, but choose + # one that's available on all platforms and doesn't write to disk + pdf(file = NULL) dev.control(displaylist = "enable") dev <- dev.cur() on.exit(dev.off(dev)) diff --git a/tests/testthat/plot-persp.R b/tests/testthat/plot-persp.R index fd93053..47bfa2c 100644 --- a/tests/testthat/plot-persp.R +++ b/tests/testthat/plot-persp.R @@ -1,4 +1,4 @@ -x <- seq(-10, 10, length = 30) +x <- seq(-10, 10, length.out = 30) y <- x ff <- function(x,y) { r <- sqrt(x^2 + y^2); 10 * sin(r) / r } z <- outer(x, y, ff) diff --git a/tests/testthat/test-graphics.R b/tests/testthat/test-graphics.R index 5768764..f13360f 100644 --- a/tests/testthat/test-graphics.R +++ b/tests/testthat/test-graphics.R @@ -132,14 +132,14 @@ test_that("by default, evaluate() always records plots regardless of the device" }) test_that("Rplots.pdf files are not created", { - op <- options(device = pdf) - on.exit(options(op)) - evaluate(file("plot.R")) + ev <- evaluate("plot(1)") expect_false(file.exists("Rplots.pdf")) }) # https://github.com/yihui/knitr/issues/2297 test_that("existing plots will not leak into evaluate()", { + withr::local_options(device = function() pdf(NULL)) + pdf(NULL) dev.control('enable') d <- dev.cur()