Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# ggplot2 (development version)

* Passing empty unmapped aesthetics to layers raises a warning instead of
throwing an error (@teunbrand, #6009).
* Missing values from discrete palettes are no longer translated
(@teunbrand, #5929).
* Fixed bug in `facet_grid(margins = TRUE)` when using expresssions
Expand Down
9 changes: 9 additions & 0 deletions R/layer.R
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,15 @@ layer <- function(geom = NULL, stat = NULL,
if (any(pattern)) {
aes_params[pattern] <- lapply(aes_params[pattern], list)
}
# Drop empty aesthetics
empty_aes <- names(aes_params)[lengths(aes_params) == 0]
if (length(empty_aes) > 0) {
cli::cli_warn(
"Ignoring empty aesthetic{?s}: {.arg {empty_aes}}.",
call = call_env
)
aes_params <- aes_params[setdiff(names(aes_params), empty_aes)]
}

# Warn about extra params and aesthetics
extra_param <- setdiff(names(params), all)
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 @@ -25,6 +25,13 @@ test_that("unknown aesthetics create warning", {
expect_warning(geom_point(aes(blah = "red")), "unknown aesthetics")
})

test_that("empty aesthetics create warning", {
expect_warning(
geom_point(fill = NULL, shape = character()),
"Ignoring empty aesthetics"
)
})

test_that("invalid aesthetics throws errors", {
# We want to test error and ignore the scale search message
suppressMessages({
Expand Down
Loading