From bf25698ed68ebc364e7257f13071fcee46b792ce Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Thu, 9 Oct 2025 11:46:48 +0200 Subject: [PATCH 1/2] move warning about empty aesthetics --- R/layer.R | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/R/layer.R b/R/layer.R index d241f69af5..b2924c6cd9 100644 --- a/R/layer.R +++ b/R/layer.R @@ -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) @@ -784,6 +775,16 @@ Layer <- ggproto("Layer", NULL, # Combine aesthetics, defaults, & params if (empty(data)) return(data) + # 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)] From 92eff3733e95d1137bb3482f044700a4a379a6b0 Mon Sep 17 00:00:00 2001 From: Teun van den Brand Date: Thu, 9 Oct 2025 11:47:03 +0200 Subject: [PATCH 2/2] test for warning during build phase --- tests/testthat/test-layer.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-layer.R b/tests/testthat/test-layer.R index efa1265b3f..9528c2927f 100644 --- a/tests/testthat/test-layer.R +++ b/tests/testthat/test-layer.R @@ -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", {