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

Adding NULL to a theme #6291

Open
teunbrand opened this issue Jan 22, 2025 · 0 comments · May be fixed by #6296
Open

Adding NULL to a theme #6291

teunbrand opened this issue Jan 22, 2025 · 0 comments · May be fixed by #6296

Comments

@teunbrand
Copy link
Collaborator

This was identified in #6287 and affects 16 packages.

You can add NULL to a regular theme and it will be a no-op.
However, some packages don't also have the "gg" class for their themes, which causes problems when adding NULL.

library(ggplot2)

class(theme())
#> [1] "theme" "gg"
class(survminer::theme_survminer())
#> [1] "theme"

theme() + NULL
#>  Named list()
#>  - attr(*, "class")= chr [1:2] "theme" "gg"
#>  - attr(*, "complete")= logi FALSE
#>  - attr(*, "validate")= logi TRUE
survminer::theme_survminer() + NULL
#> Error in survminer::theme_survminer() + NULL: non-numeric argument to binary operator

Created on 2025-01-22 with reprex v2.1.1

This can become a problem in the chunk of code below:

ggplot2/R/guides-.R

Lines 541 to 549 in 6a61201

adjust <- NULL
position <- groups$key$position[i]
if (position == "inside") {
adjust <- theme(
legend.position.inside = groups$key$coord[[i]],
legend.justification.inside = groups$key$justs[[i]]
)
}
grobs[[i]] <- self$package_box(grobs[[i]], position, theme + adjust)

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 a pull request may close this issue.

1 participant