Skip to content

Commit f135340

Browse files
author
Dana Paige Seidel
authored
Fix cryptic error messages caused by missing aesthetics (#2754)
Fixes #2637 ; Fixes #2706
1 parent 9b86cc7 commit f135340

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# ggplot2 3.0.0.9000
22

3+
* All `geom_*()` now display an informative error message when required
4+
aesthetics are missing (@dpseidel, #2637 and #2706).
5+
36
* `sec_axis()` and `dup_axis()` now return appropriate breaks for the secondary
47
axis when applied to log transformed scales (@dpseidel, #2729).
58

R/layer.r

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,15 +283,14 @@ Layer <- ggproto("Layer", NULL,
283283

284284
compute_geom_1 = function(self, data) {
285285
if (empty(data)) return(data.frame())
286-
data <- self$geom$setup_data(data, c(self$geom_params, self$aes_params))
287286

288287
check_required_aesthetics(
289288
self$geom$required_aes,
290289
c(names(data), names(self$aes_params)),
291290
snake_class(self$geom)
292291
)
293292

294-
data
293+
self$geom$setup_data(data, c(self$geom_params, self$aes_params))
295294
},
296295

297296
compute_position = function(self, data, layout) {

tests/testthat/test-layer.r

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ test_that("column vectors are allowed (#2609)", {
2626
expect_is(layer_data(p), "data.frame")
2727
})
2828

29+
test_that("missing aesthetics trigger informative error", {
30+
df <- data.frame(x = 1:10)
31+
expect_error(
32+
ggplot_build(ggplot(df) + geom_line()),
33+
"requires the following missing aesthetics:"
34+
)
35+
expect_error(
36+
ggplot_build(ggplot(df) + geom_col()),
37+
"requires the following missing aesthetics:"
38+
)
39+
})
40+
2941
# Data extraction ---------------------------------------------------------
3042

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

0 commit comments

Comments
 (0)