Skip to content
Merged
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
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
get backticks, and long expressions are abbreviated with `...`
(@yutannihilation, #2981).

* Aesthetic mappings now accept functions that return `NULL` (@yutannihilation,
#2997)

# ggplot2 3.1.0

## Breaking changes
Expand Down
2 changes: 1 addition & 1 deletion R/layer.r
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ Layer <- ggproto("Layer", NULL,
scales_add_defaults(plot$scales, data, aesthetics, plot$plot_env)

# Evaluate and check aesthetics
aesthetics <- compact(aesthetics)
evaled <- lapply(aesthetics, rlang::eval_tidy, data = data)
evaled <- compact(evaled)

n <- nrow(data)
if (n == 0) {
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/test-layer.r
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ test_that("missing aesthetics trigger informative error", {
)
})

test_that("if an aes is mapped to a function that returns NULL, it is removed", {
df <- data.frame(x = 1:10)
null <- function(...) NULL
p <- cdata(ggplot(df, aes(x, null())))
expect_identical(names(p[[1]]), c("x", "PANEL", "group"))
})

# Data extraction ---------------------------------------------------------

test_that("layer_data returns a data.frame", {
Expand Down