Skip to content

Duplicated aes warning with multiple modified aesthetics #4707

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Apr 29, 2022
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Imports:
lifecycle,
MASS,
mgcv,
rlang (>= 0.4.10),
rlang (>= 1.0.0),
scales (>= 0.5.0),
stats,
tibble,
Expand Down 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
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

16 changes: 16 additions & 0 deletions tests/testthat/test-aes-calculated.r
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,19 @@ 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")
expr <- substitute(
Copy link
Member

Choose a reason for hiding this comment

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

Since I don't think you're actually doing any substitution, quote() would be more appropriate here. But I think you could also just do p <- ggplot() + ... in the expect_snapshot_warning().

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good points, I wasn't aware of this, so thanks!

ggplot(df, aes(x, y, label = lab)) +
geom_label(
aes(colour = stage(lab, after_scale = colour),
color = after_scale(color))
)
)
# One warning in plot code due to evaluation of `aes()`
expect_snapshot_warning(p <- eval(expr))
# Two warnings in building due to `stage()`/`after_scale()`
Copy link
Member

Choose a reason for hiding this comment

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

I only see one warning in the test?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah indeed! The second of those warnings only occurred when ggplot_build(p) was evaluated in the console, due to automatically printing the result. I've now disabled the legend, which caused that extra warning.

expect_snapshot_warning(ggplot_build(p))
})