Skip to content
Open
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion R/block.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 0 additions & 14 deletions R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
23 changes: 1 addition & 22 deletions tests/testit/test-plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))))
})

Expand Down
Loading