Skip to content

Commit a6c22e7

Browse files
authored
Duplicated aes warning with multiple modified aesthetics (#4707)
1 parent 21df8dc commit a6c22e7

File tree

5 files changed

+34
-2
lines changed

5 files changed

+34
-2
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Suggests:
6868
rpart,
6969
sf (>= 0.7-3),
7070
svglite (>= 1.2.0.9001),
71-
testthat (>= 3.0.0),
71+
testthat (>= 3.1.2),
7272
vdiffr (>= 1.0.0),
7373
xml2
7474
Enhances:

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# ggplot2 (development version)
22

3+
* Using multiple modified aesthetics correctly will no longer trigger warnings.
4+
If used incorrectly, the warning will now report the duplicated aesthetic
5+
instead of `NA` (@teunbrand, #4707).
6+
37
* `...` supports `rlang::list2` dynamic dots in all public functions. (@mone27, #4764)
48

59
* `theme()` now has a `strip.clip` argument, that can be set to `"off"` to

R/geom-.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ Geom <- ggproto("Geom",
143143
abort(msg)
144144
}
145145

146-
names(modified_aes) <- rename_aes(names(modifiers))
146+
names(modified_aes) <- names(rename_aes(modifiers))
147147
modified_aes <- new_data_frame(compact(modified_aes))
148148

149149
data <- cunion(modified_aes, data)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# staged aesthetics warn appropriately for duplicated names
2+
3+
Duplicated aesthetics after name standardisation: colour
4+
5+
---
6+
7+
Duplicated aesthetics after name standardisation: colour
8+

tests/testthat/test-aes-calculated.r

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,23 @@ test_that("make_labels() deprases mappings properly", {
4949
expect_identical(make_labels(aes(x = 1)), list(x = "x"))
5050
expect_identical(make_labels(aes(x = NULL)), list(x = "x"))
5151
})
52+
53+
test_that("staged aesthetics warn appropriately for duplicated names", {
54+
# Test should *not* report `NA` as the duplicated aes (#4707)
55+
df <- data.frame(x = 1, y = 1, lab = "test")
56+
57+
# One warning in plot code due to evaluation of `aes()`
58+
expect_snapshot_warning(
59+
p <- ggplot(df, aes(x, y, label = lab)) +
60+
geom_label(
61+
aes(colour = stage(lab, after_scale = colour),
62+
color = after_scale(color))
63+
) +
64+
# Guide would trigger another warning when plot is printed, due to the
65+
# `guide_geom.legend` also using `Geom$use_defaults` method, which we
66+
# test next
67+
guides(colour = "none")
68+
)
69+
# One warning in building due to `stage()`/`after_scale()`
70+
expect_snapshot_warning(ggplot_build(p))
71+
})

0 commit comments

Comments
 (0)