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

Make sure that expressions are reencoded as expressions when collapsed #4418

Merged
merged 3 commits into from
Apr 15, 2021

Conversation

thomasp85
Copy link
Member

Fix #4084

There is one "issue" in that parsing is either, or. Right now it will re-add parsing if any label is an expression which could potentially lead to errors if there is a mix of expressions and not (I'm not sure if that is possible) and the non-expressions cannot be parsed...

Alternatively we could only do this if all labels are expressions...

library("ggplot2")

dat <- data.frame(x = 1, y = 1, a = "a", b = 1)

ggplot(dat, aes(x, y)) +
  geom_point() +
  facet_grid(
    ~ a + b,
    labeller = labeller(
      a = c("a" = "a^2"),
      .default = label_parsed,
      .multi_line = FALSE
    )
  )

Created on 2021-04-14 by the reprex package (v2.0.0)

@thomasp85 thomasp85 added this to the ggplot2 3.3.4 milestone Apr 14, 2021
@thomasp85 thomasp85 requested a review from karawoo April 14, 2021 08:05
@thomasp85
Copy link
Member Author

I decided to switch to all() instead of any() as it seems the safest

Copy link
Member

@karawoo karawoo left a comment

Choose a reason for hiding this comment

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

This seems good to me. It is possible to have a mix of expressions and non-expressions (below). But at that point the label is the combined text of both the labels, so if they aren't all expressions then I think it's a reasonable limitation to not try to parse them.

library("ggplot2")

dat <- data.frame(
  x = 1,
  y = 1,
  fruit = "apple",
  veg = "carrot",
  stringsAsFactors = TRUE
)

ggplot(dat, aes(x, y)) +
  geom_point() +
  facet_grid(
    ~ fruit + veg,
    labeller = labeller(
      fruit = c("apple" = "a^2"),
      veg = label_both,
      .default = label_parsed,
      .multi_line = FALSE
    )
  )

Created on 2021-04-14 by the reprex package (v0.3.0.9001)

@thomasp85
Copy link
Member Author

yeah, it is not possible to mix it without a very big rewrite of the strip rendering system which I don't think is warranted at this point

@thomasp85 thomasp85 merged commit 9cfb0b3 into master Apr 15, 2021
@thomasp85 thomasp85 deleted the issue-4084-multiline-label-parse branch April 15, 2021 07:21
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.

Combined facet labels aren't parsed when .multi_line = FALSE
2 participants