Skip to content
Open
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
19 changes: 10 additions & 9 deletions R/layer.R
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,6 @@ 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 Expand Up @@ -784,6 +775,16 @@ Layer <- ggproto("Layer", NULL,
# Combine aesthetics, defaults, & params
if (empty(data)) return(data)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This prevents warning to pop up inappropriately.


# Drop empty aesthetics
empty_aes <- names(params)[lengths(params) == 0]
if (length(empty_aes) > 0) {
cli::cli_warn(
"Ignoring empty aesthetic{?s}: {.arg {empty_aes}}.",
call = self$constructor
)
params <- params[setdiff(names(params), empty_aes)]
}

aesthetics <- self$computed_mapping
modifiers <- aesthetics[is_scaled_aes(aesthetics) | is_staged_aes(aesthetics) | is_themed_aes(aesthetics)]

Expand Down
3 changes: 2 additions & 1 deletion tests/testthat/test-layer.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ test_that("unknown aesthetics create warning", {
})

test_that("empty aesthetics create warning", {
expect_snapshot_warning(geom_point(fill = NULL, shape = character()))
p <- ggplot(mtcars) + geom_point(aes(disp, mpg), fill = NULL, shape = character())
expect_snapshot_warning(ggplot_build(p))
})

test_that("invalid aesthetics throws errors", {
Expand Down