Skip to content

Commit b5dee5a

Browse files
Allow using functions that return NULL in aes() (#2997)
1 parent 391c350 commit b5dee5a

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
get backticks, and long expressions are abbreviated with `...`
77
(@yutannihilation, #2981).
88

9+
* Aesthetic mappings now accept functions that return `NULL` (@yutannihilation,
10+
#2997)
11+
912
# ggplot2 3.1.0
1013

1114
## Breaking changes

R/layer.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ Layer <- ggproto("Layer", NULL,
218218
scales_add_defaults(plot$scales, data, aesthetics, plot$plot_env)
219219

220220
# Evaluate and check aesthetics
221-
aesthetics <- compact(aesthetics)
222221
evaled <- lapply(aesthetics, rlang::eval_tidy, data = data)
222+
evaled <- compact(evaled)
223223

224224
n <- nrow(data)
225225
if (n == 0) {

tests/testthat/test-layer.r

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ test_that("missing aesthetics trigger informative error", {
3838
)
3939
})
4040

41+
test_that("if an aes is mapped to a function that returns NULL, it is removed", {
42+
df <- data.frame(x = 1:10)
43+
null <- function(...) NULL
44+
p <- cdata(ggplot(df, aes(x, null())))
45+
expect_identical(names(p[[1]]), c("x", "PANEL", "group"))
46+
})
47+
4148
# Data extraction ---------------------------------------------------------
4249

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

0 commit comments

Comments
 (0)