Skip to content
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Suggests:
rpart,
sf (>= 0.7-3),
svglite (>= 1.2.0.9001),
testthat (>= 3.0.0),
testthat (>= 3.1.2),
vdiffr (>= 1.0.0),
xml2
Enhances:
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# ggplot2 (development version)

* Using multiple modified aesthetics correctly will no longer trigger warnings.
If used incorrectly, the warning will now report the duplicated aesthetic
instead of `NA` (@teunbrand, #4707).

* `...` supports `rlang::list2` dynamic dots in all public functions. (@mone27, #4764)

* `theme()` now has a `strip.clip` argument, that can be set to `"off"` to
Expand Down
2 changes: 1 addition & 1 deletion R/geom-.r
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ Geom <- ggproto("Geom",
abort(msg)
}

names(modified_aes) <- rename_aes(names(modifiers))
names(modified_aes) <- names(rename_aes(modifiers))
modified_aes <- new_data_frame(compact(modified_aes))

data <- cunion(modified_aes, data)
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/_snaps/aes-calculated.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# staged aesthetics warn appropriately for duplicated names

Duplicated aesthetics after name standardisation: colour

---

Duplicated aesthetics after name standardisation: colour

20 changes: 20 additions & 0 deletions tests/testthat/test-aes-calculated.r
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,23 @@ test_that("make_labels() deprases mappings properly", {
expect_identical(make_labels(aes(x = 1)), list(x = "x"))
expect_identical(make_labels(aes(x = NULL)), list(x = "x"))
})

test_that("staged aesthetics warn appropriately for duplicated names", {
# Test should *not* report `NA` as the duplicated aes (#4707)
df <- data.frame(x = 1, y = 1, lab = "test")

# One warning in plot code due to evaluation of `aes()`
expect_snapshot_warning(
p <- ggplot(df, aes(x, y, label = lab)) +
geom_label(
aes(colour = stage(lab, after_scale = colour),
color = after_scale(color))
) +
# Guide would trigger another warning when plot is printed, due to the
# `guide_geom.legend` also using `Geom$use_defaults` method, which we
# test next
guides(colour = "none")
)
# One warning in building due to `stage()`/`after_scale()`
expect_snapshot_warning(ggplot_build(p))
})