Skip to content
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

Unknown theme elements throw warnings instead of errors #5743

Merged
merged 5 commits into from
Mar 18, 2024

Conversation

teunbrand
Copy link
Collaborator

This PR aims to fix #5719.

Briefly, when declaring an unknown theme element, we throw a warning instead of error. The offending theme element is then removed from the theme.

This is more gentle if you make a typo or for us if we want to deprecate theme arguments.

Reprex from the issue:

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

ggplot(mpg, aes(displ, hwy)) +
  geom_point() +
  theme(foobar = "qux")
#> Warning in plot_theme(plot): The `foobar` theme element is not defined in the
#> element hierarchy.

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

@teunbrand teunbrand added this to the ggplot2 3.5.1 milestone Mar 5, 2024
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.

Apart from the comment LGTM

@@ -293,7 +293,7 @@ test_that("incorrect theme specifications throw meaningful errors", {
test_that("element tree can be modified", {
# we cannot add a new theme element without modifying the element tree
p <- ggplot() + theme(blablabla = element_text(colour = "red"))
expect_snapshot_error(print(p))
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't this require an update of the snapshot

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The message is exactly the same so the snapshot file hasn't changed

Copy link
Member

Choose a reason for hiding this comment

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

👍

@teunbrand teunbrand merged commit 50b3515 into tidyverse:main Mar 18, 2024
12 checks passed
@teunbrand teunbrand deleted the theme_error_to_warning branch March 18, 2024 10:32
@teunbrand teunbrand mentioned this pull request Apr 3, 2024
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 undefined theme elements throw a warning instead of an error?
2 participants