Skip to content

Commit 339462c

Browse files
authored
Don't use I() to format the layer call (#4961)
1 parent 6434c1e commit 339462c

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

R/plot-build.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ by_layer <- function(f, layers, data, step = NULL) {
421421
out[[i]] <- f(l = layers[[i]], d = data[[i]])
422422
},
423423
error = function(cnd) {
424-
cli::cli_abort(c("Problem while {step}.", "i" = "Error occurred in the {ordinal(i)} layer."), call = I(layers[[i]]$constructor), parent = cnd)
424+
cli::cli_abort(c("Problem while {step}.", "i" = "Error occurred in the {ordinal(i)} layer."), call = layers[[i]]$constructor, parent = cnd)
425425
}
426426
)
427427
out

tests/testthat/_snaps/layer.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,21 @@
6969
x `fill = NULL`
7070
i Did you map your stat in the wrong layer?
7171

72+
# layer reports the error with correct index etc
73+
74+
Problem while setting up geom.
75+
i Error occurred in the 1st layer.
76+
Caused by error in `compute_geom_1()`:
77+
! `geom_linerange()` requires the following missing aesthetics: ymax or xmin and xmax
78+
79+
---
80+
81+
Problem while converting geom to grob.
82+
i Error occurred in the 2nd layer.
83+
Caused by error in `draw_group()`:
84+
! Can only draw one boxplot per group
85+
i Did you forget `aes(group = ...)`?
86+
7287
# layer_data returns a data.frame
7388

7489
`layer_data()` must return a <data.frame>

tests/testthat/test-layer.r

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,21 @@ test_that("retransform works on computed aesthetics in `map_statistic`", {
108108
expect_equal(layer_data(p)$y, c(9, 25))
109109
})
110110

111+
test_that("layer reports the error with correct index etc", {
112+
p <- ggplot(mtcars) + geom_linerange(aes(disp, mpg), ymin = 2)
113+
114+
expect_snapshot_error(ggplotGrob(p))
115+
116+
p <- ggplot(
117+
data_frame(x = "one value", y = 3, value = 4:6),
118+
aes(x, ymin = 0, lower = 1, middle = y, upper = value, ymax = 10)
119+
) +
120+
geom_point(aes(x = x, y = y), inherit.aes = FALSE) +
121+
geom_boxplot(stat = "identity")
122+
123+
expect_snapshot_error(ggplotGrob(p))
124+
})
125+
111126
# Data extraction ---------------------------------------------------------
112127

113128
test_that("layer_data returns a data.frame", {

0 commit comments

Comments
 (0)