Skip to content

Fix labeller to pass .default for lookups (#4031) #4032

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

Merged
merged 4 commits into from
Jun 23, 2020
Merged

Fix labeller to pass .default for lookups (#4031) #4032

merged 4 commits into from
Jun 23, 2020

Conversation

waltersom
Copy link
Contributor

@waltersom waltersom commented May 27, 2020

Pass .default to as_labeller even when margin_labeller is null, such as
when using named arguments for a lookup table.

This should make the behaviour match the documentation.

Fixes #4031

Pass .default to as_labeller even when margin_labeller is null, such as
when using named arguements for a lookup table.
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.

Thanks @waltersom! Could you please put space around the = sign (following tidyverse style), and add a bullet to NEWS.md that briefly describes the change and ends with (@​yourname, #issuenumber)?

@clauswilke
Copy link
Member

While we're touching this code, I think we should also consider whether .multi_line should be forwarded to as_labeller as well.

@waltersom
Copy link
Contributor Author

@karawoo I have made the requested changes.

Also @clauswilke, I was looking at also passing .multi_line, however this was more complicated, and more work is required for that. A problem is that if .multi_line==FALSE, when using label_parsed, collapse_label_lines is eventually called on the output, which converts any expression()s to characters. Further, label_parsed adds list() around the argument to expression(), which I don't fully understand.

@waltersom waltersom requested a review from karawoo June 8, 2020 04:40
@karawoo
Copy link
Member

karawoo commented Jun 13, 2020

Hmm, I see what you mean @waltersom. The .multi_line issue is more complicated. Using the example from the original issue with current ggplot2, .multi_line = FALSE gives the plot below, and this PR doesn't change that:

library("ggplot2")

tdf <- data.frame(
  x = c(1, 2, 3, 4),
  y = c(4, 3, 2, 1),
  a = c(0, 1, 0, 1),
  b = c(1, 2, 2, 1)
)

ggplot(tdf, aes(x, y)) +
  geom_point() +
  facet_grid(
    ~ a + b,
    labeller = labeller(
      a = c(`0` = "a^2", `1` = "a[2]"),
      b = c(`1` = "One", `2` = "Two"),
      .default = label_parsed,
      .multi_line = FALSE
    )
  )

If we just passed along .multi_line to the line you've edited, it becomes:

ggplot(tdf, aes(x, y)) +
  geom_point() +
  facet_grid(
    ~ a + b,
    labeller = labeller(
      a = c(`0` = "a^2", `1` = "a[2]"),
      b = c(`1` = "One", `2` = "Two"),
      .default = label_parsed,
      .multi_line = FALSE
    )
  )

I'd be inclined to merge this and open a separate issue for the .multi_line problem, but what do you think @clauswilke?

@clauswilke
Copy link
Member

This seems fine by me. The only reservation I have is that I don't know where we are in the current release cycle. Is it fine to merge into master or should we wait?

@karawoo
Copy link
Member

karawoo commented Jun 14, 2020

Yeah, let's wait until this release is finished

@karawoo
Copy link
Member

karawoo commented Jun 23, 2020

(CI failures are unrelated)

@karawoo karawoo merged commit 7d05fa3 into tidyverse:master Jun 23, 2020
@yutannihilation
Copy link
Member

(For failures, macOS runner will keep failing for a while until the R 4.0.2 installer is reliably available.)

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.

facet labellers not calling default
4 participants