Skip to content

theme() supports splicing arguments #5543

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
Dec 4, 2023

Conversation

teunbrand
Copy link
Collaborator

This PR aims to fix #5542.

Briefly, ... is moved to the first argument of the theme (which is technically a breaking change, I suppose), so that it can catch splicing operators. Then find_args(), which does the argument collection, just uses list2() to support the splicing.

Reprex from #5542:

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

red_axis <- list(
  axis.line = element_line(colour = "red"),
  axis.text = element_text(colour = "red"),
  axis.ticks = element_line(colour = "red"),
  axis.title = element_text(colour = "red")
)

ggplot(mpg, aes(displ, hwy)) +
  geom_point() +
  theme(!!!red_axis)

Created on 2023-11-28 with reprex v2.0.2

@teunbrand teunbrand added this to the ggplot2 3.5.0 milestone Nov 29, 2023
@teunbrand teunbrand requested a review from thomasp85 November 29, 2023 08:06
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.

I cannot imagine anyone using theme() with position matching of args so this should be safe

@teunbrand
Copy link
Collaborator Author

Thanks for the review Thomas!

@teunbrand teunbrand merged commit 6df5cd4 into tidyverse:main Dec 4, 2023
@teunbrand teunbrand deleted the theme_splicing branch December 4, 2023 15:27
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.

Should theme() support argument splicing?
2 participants