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

Demote errors in legend modified expressions #6267

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

teunbrand
Copy link
Collaborator

This PR aims to fix #6264.

When we have modified expressions with e.g. stage() that fail to evaluate, we demote the error to a warning and don't apply these expressions.

@yjunechoe
Copy link
Contributor

Thanks -- this works for my use-case!

I think the try_fetch() might be implemented too loosely here, though, as it seems to also demote genuine evaluation errors with after-scale expressions on the layer data.

p <- ggplot(mpg, aes(drv)) +
  geom_bar(
    aes(fill = after_scale(stop())),
    # show.legend = FALSE
  )

On main:

p
#> Error in `geom_bar()`:
#> ! Problem while setting up geom aesthetics.
#> ℹ Error occurred in the 1st layer.
#> Caused by error in `after_scale()`:

(plot fails to build)

On branch:

p
#> Warning: Unable to apply legend modifications.
#> Caused by error in `after_scale()`:

image


May be out of scope and may not need this as part of the solution, but I wonder whether it's worth considering passing some kind of a flag to Layer$compute_geom_2()/Geom$use_defaults() to indicate whether the data represents the layer geom or the guide.

@teunbrand
Copy link
Collaborator Author

You raise a good point, though IMO the error message is overspecific. If we just say the staged modifications failed, without mentioning legend or layer, we needn't fuss about passing along context.

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.

Inappropriate scoping of after_scale variables when resolving legend data
2 participants