Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion R/watchout.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should compare last_plot[[2]] and plot[[2]] just to be explicit?

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()
}

Expand Down
17 changes: 17 additions & 0 deletions tests/testthat/test-graphics.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 ------------------------------------------------

Expand Down