Skip to content

Commit d37432f

Browse files
hadleycderv
authored andcommitted
Use evaluate 1.0.0
Including new `trim_intermediates_plot()` function. Although now that I look closely at this I notice that rgl provides a `is_low_change()` method so that this might be a breaking change, and I need to consider this in evaluate.
1 parent bc64049 commit d37432f

File tree

4 files changed

+3
-38
lines changed

4 files changed

+3
-38
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ Description: Provides a general-purpose tool for dynamic report generation in R
116116
Depends:
117117
R (>= 3.6.0)
118118
Imports:
119-
evaluate (>= 0.15),
119+
evaluate (>= 1.0.0),
120120
highr (>= 0.11),
121121
methods,
122122
tools,

R/block.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ rearrange_figs = function(res, keep, idx, show) {
495495
keep,
496496
first = res[-tail(which(figs), -1L)],
497497
last = res[-head(which(figs), -1L)],
498-
high = merge_low_plot(res, figs), # merge low-level plotting changes
498+
high = evaluate::trim_intermediate_plots(res), # merge low-level plotting changes
499499
index = {
500500
i = which(figs)[-idx]
501501
if (length(i) > 0) res[-i] else res # keep only selected

R/plot.R

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -220,20 +220,6 @@ load_device = function(name, package, dpi = NULL) {
220220
}
221221

222222

223-
# merge low-level plotting changes
224-
merge_low_plot = function(x, idx = sapply(x, evaluate::is.recordedplot)) {
225-
idx = which(idx); n = length(idx); m = NULL # store indices that will be removed
226-
if (n <= 1) return(x)
227-
i1 = idx[1]; i2 = idx[2] # compare plots sequentially
228-
for (i in 1:(n - 1)) {
229-
# remove the previous plot and move its index to the next plot
230-
if (is_low_change(x[[i1]], x[[i2]])) m = c(m, i1)
231-
i1 = idx[i + 1]
232-
i2 = idx[i + 2]
233-
}
234-
if (is.null(m)) x else x[-m]
235-
}
236-
237223
#' Compare two recorded plots
238224
#'
239225
#' Check if one plot only contains a low-level update of another plot.

tests/testit/test-plot.R

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,13 @@ assert('blank plots are removed', {
1414
(identical(classes(res), 'source'))
1515
})
1616

17-
assert('plots generated by par(), palette() or layout() are removed', {
18-
res = evaluate('par(mfrow = c(1, 2))\npie(islands)\nbarplot(islands)')
19-
(identical(classes(res), rep(c('source', 'recordedplot'), c(3, 1))))
20-
res = evaluate('layout(t(1:2))\npie(islands)\nbarplot(islands)')
21-
(identical(classes(res), rep(c('source', 'recordedplot'), c(3, 1))))
22-
res = evaluate('pie(islands)\nbarplot(islands)\npar(mfrow = c(1, 2))')
23-
res = merge_low_plot(res)
24-
(identical(classes(res), rep(c('source', 'recordedplot'), length = 5)))
25-
res = evaluate('pie(islands)\npar(cex.main=1.2)\nbarplot(islands)')
26-
res = merge_low_plot(res)
27-
(identical(classes(res), c('source', 'recordedplot')[c(1, 2, 1, 1, 2)]))
28-
res = evaluate('par(cex.main=1.2)\npalette(c("red","black"))\nbarplot(islands)')
29-
(identical(classes(res), rep(c('source', 'recordedplot'), c(3, 1))))
30-
})
31-
32-
assert('merge low-level changes', {
33-
res = evaluate('plot(1)\npoints(1.1, 1.1)')
34-
(classes(res) %==% rep(c('source', 'recordedplot'), 2))
35-
(classes(merge_low_plot(res)) %==% rep(c('source', 'recordedplot'), c(2, 1)))
36-
})
37-
3817
assert('captures grid graphics', {
3918
res = evaluate('library(grid)
4019
grid.newpage()
4120
grid.rect(gp=gpar(fill="grey"))
4221
grid.rect(gp=gpar(fill="red"))')
4322
(classes(res) %==% c('source', 'recordedplot')[c(1, 1, 1, 2, 1, 2)])
44-
res = merge_low_plot(res)
23+
res = evaluate::trim_intermediate_plots(res)
4524
(identical(classes(res), rep(c('source', 'recordedplot'), c(4, 1))))
4625
})
4726

0 commit comments

Comments
 (0)