diff --git a/R/watchout.R b/R/watchout.R index 0baafd9..1ff317f 100644 --- a/R/watchout.R +++ b/R/watchout.R @@ -66,11 +66,22 @@ watchout <- function( } plot <- recordPlot() + + # Detect visual change on the new plot if (!makes_visual_change(plot[[1]])) { return() } - if (!looks_different(last_plot[[1]], plot[[1]])) { + # Are recorded plots identical? + if (identical(last_plot, plot)) { + return() + } + + # Compare the display lists for differences + # when they are not identical + old_dl <- last_plot[[1]] + new_dl <- plot[[1]] + if (!identical(old_dl, new_dl) && !looks_different(old_dl, new_dl)) { return() } diff --git a/tests/testthat/test-graphics.R b/tests/testthat/test-graphics.R index ae08fb1..98e8394 100644 --- a/tests/testthat/test-graphics.R +++ b/tests/testthat/test-graphics.R @@ -227,6 +227,23 @@ test_that("evaluate ignores plots created in new device", { expect_output_types(ev, c("source", "source", "source", "source", "plot")) }) +test_that("evaluate keeps identical plots", { + ev <- evaluate(function() { + plot(1) + plot(1) + }) + expect_output_types(ev, c("source", "plot", "source", "plot")) + + skip_if_not_installed("ggplot2") + library(ggplot2) + df <- data.frame(x = 1, y = 1) + ev <- evaluate(function() { + ggplot(df) + geom_point(aes(x, y)) + ggplot(df) + geom_point(aes(x, y)) + }) + expect_output_types(ev, c("source", "plot", "source", "plot")) +}) + # trim_intermediate_plots ------------------------------------------------