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

Static expressions #6294

Closed
teunbrand opened this issue Jan 22, 2025 · 2 comments
Closed

Static expressions #6294

teunbrand opened this issue Jan 22, 2025 · 2 comments

Comments

@teunbrand
Copy link
Collaborator

This problem was identified in #6287 and affects 8 packages.

Generally, ggplot2 does not accept expressions as aesthetics.

library(ggplot2)

df <- data.frame(x = 1:2, y = 2:3)

ggplot(df, aes(x, y)) +
  geom_text(aes(label = expression(foo, bar)))
#> Don't know how to automatically pick scale for object of type <expression>.
#> Defaulting to continuous.
#> Error in `geom_text()`:
#> ! Problem while computing aesthetics.
#> ℹ Error occurred in the 1st layer.
#> Caused by error in `compute_aesthetics()`:
#> ! Aesthetics are not valid data columns.
#> ✖ The following aesthetics are invalid:
#> ✖ `label = expression(foo, bar)`
#> ℹ Did you mistype the name of a data column or forget to add `after_stat()`?

However, with the current CRAN ggplot2, you can circumvent this limitation by passing the label outside the mapping.

ggplot(df, aes(x, y)) +
  geom_text(label = expression(foo, bar))
#> Warning in is.na(x): is.na() applied to non-(list or vector) of type
#> 'expression'

In the dev version, we also reject expressions outside the mapping.

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

ggplot(df, aes(x, y)) +
  geom_text(label = expression(foo, bar))
#> Error in `geom_text()`:
#> ! Problem while setting up geom aesthetics.
#> ℹ Error occurred in the 1st layer.
#> Caused by error in `list_sizes()` at ggplot2/R/geom-.R:273:3:
#> ! `x$label` must be a vector, not an expression vector.

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

Our increased strictness becomes a problem for reverse dependencies. I'm unsure wether ggplot2 should accommodate or the dependencies should follow ggplot2's conventions.

@teunbrand
Copy link
Collaborator Author

We shouldn't change the vctrs behaviour, but we should probably send out PRs/issues to packages.

@teunbrand
Copy link
Collaborator Author

Of the 8 packages mentioned:

  • 3 did not actually have the described problem, they just threw a similar error. The problem was mostly using default_aes fields. They've been sent PRs.
  • 3 packages did have this problem. They've been sent PRs.
  • 2 packages are not on GitHub and their authors have been emailed.

This concludes what we can do about this problem from ggplot2's viewport, so I'm going to close this issue.

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

No branches or pull requests

1 participant