Skip to content

after_*() length checks #5902

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 5 commits into from
May 22, 2024
Merged

Conversation

teunbrand
Copy link
Collaborator

This PR aims to fix #5901.

Briefly, when after_stat() or after_scale() produce aesthetics of the wrong length, a warning is thrown that the function could not be applied.

The reprex from the issue now renders with a warning:

devtools::load_all("~/packages/ggplot2")
#> ℹ Loading ggplot2

ggplot(mpg[15:16, ], aes(displ, hwy)) +
  geom_point(
    aes(colour = after_scale(c("red", "green", "blue")))
  )
#> Warning: Failed to apply `after_scale()` for the following aesthetic: colour.

Created on 2024-05-22 with reprex v2.1.0

I have an alternate agenda with this PR.
Moving this check into Geom$use_defaults() frees us from having to do so in the legend code, allowing a simplification I ultimately need for #5833.

@teunbrand teunbrand requested a review from thomasp85 May 22, 2024 12:05
Copy link
Member

@thomasp85 thomasp85 left a comment

Choose a reason for hiding this comment

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

LGTM

@teunbrand
Copy link
Collaborator Author

Thanks for the review Thomas!

@teunbrand teunbrand merged commit 0d0dc62 into tidyverse:main May 22, 2024
11 checks passed
@teunbrand teunbrand deleted the after_length_checks branch May 22, 2024 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Length check for after_scale() aesthetics
2 participants