diff --git a/DESCRIPTION b/DESCRIPTION index a8225634fd..16e5a30f74 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -116,7 +116,7 @@ Description: Provides a general-purpose tool for dynamic report generation in R Depends: R (>= 3.6.0) Imports: - evaluate (>= 0.15), + evaluate (>= 1.0.0), highr (>= 0.11), methods, tools, diff --git a/R/block.R b/R/block.R index 28ea201183..0b3556a7e4 100644 --- a/R/block.R +++ b/R/block.R @@ -495,7 +495,7 @@ rearrange_figs = function(res, keep, idx, show) { keep, first = res[-tail(which(figs), -1L)], last = res[-head(which(figs), -1L)], - high = merge_low_plot(res, figs), # merge low-level plotting changes + high = evaluate::trim_intermediate_plots(res), # merge low-level plotting changes index = { i = which(figs)[-idx] if (length(i) > 0) res[-i] else res # keep only selected diff --git a/R/plot.R b/R/plot.R index de47280b9a..e6ab6afd53 100644 --- a/R/plot.R +++ b/R/plot.R @@ -220,20 +220,6 @@ load_device = function(name, package, dpi = NULL) { } -# merge low-level plotting changes -merge_low_plot = function(x, idx = sapply(x, evaluate::is.recordedplot)) { - idx = which(idx); n = length(idx); m = NULL # store indices that will be removed - if (n <= 1) return(x) - i1 = idx[1]; i2 = idx[2] # compare plots sequentially - for (i in 1:(n - 1)) { - # remove the previous plot and move its index to the next plot - if (is_low_change(x[[i1]], x[[i2]])) m = c(m, i1) - i1 = idx[i + 1] - i2 = idx[i + 2] - } - if (is.null(m)) x else x[-m] -} - #' Compare two recorded plots #' #' Check if one plot only contains a low-level update of another plot. diff --git a/tests/testit/test-plot.R b/tests/testit/test-plot.R index 9275ba5b8e..18957c7d72 100644 --- a/tests/testit/test-plot.R +++ b/tests/testit/test-plot.R @@ -14,34 +14,13 @@ assert('blank plots are removed', { (identical(classes(res), 'source')) }) -assert('plots generated by par(), palette() or layout() are removed', { - res = evaluate('par(mfrow = c(1, 2))\npie(islands)\nbarplot(islands)') - (identical(classes(res), rep(c('source', 'recordedplot'), c(3, 1)))) - res = evaluate('layout(t(1:2))\npie(islands)\nbarplot(islands)') - (identical(classes(res), rep(c('source', 'recordedplot'), c(3, 1)))) - res = evaluate('pie(islands)\nbarplot(islands)\npar(mfrow = c(1, 2))') - res = merge_low_plot(res) - (identical(classes(res), rep(c('source', 'recordedplot'), length = 5))) - res = evaluate('pie(islands)\npar(cex.main=1.2)\nbarplot(islands)') - res = merge_low_plot(res) - (identical(classes(res), c('source', 'recordedplot')[c(1, 2, 1, 1, 2)])) - res = evaluate('par(cex.main=1.2)\npalette(c("red","black"))\nbarplot(islands)') - (identical(classes(res), rep(c('source', 'recordedplot'), c(3, 1)))) -}) - -assert('merge low-level changes', { - res = evaluate('plot(1)\npoints(1.1, 1.1)') - (classes(res) %==% rep(c('source', 'recordedplot'), 2)) - (classes(merge_low_plot(res)) %==% rep(c('source', 'recordedplot'), c(2, 1))) -}) - assert('captures grid graphics', { res = evaluate('library(grid) grid.newpage() grid.rect(gp=gpar(fill="grey")) grid.rect(gp=gpar(fill="red"))') (classes(res) %==% c('source', 'recordedplot')[c(1, 1, 1, 2, 1, 2)]) - res = merge_low_plot(res) + res = evaluate::trim_intermediate_plots(res) (identical(classes(res), rep(c('source', 'recordedplot'), c(4, 1)))) })