Skip to content

refactor show.legend code #3652

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 3 commits into from
Dec 6, 2019
Merged

Conversation

clauswilke
Copy link
Member

Simplifies and unifies the code that the various guides use to determine which layers to include and exclude. This PR came out of this discussion: https://github.com/tidyverse/ggplot2/pull/3646/files#r353483822

@clauswilke
Copy link
Member Author

@thomasp85 Could you take a look at this PR, and maybe also the discussion that prompted it (see link above)?

Copy link
Member

@yutannihilation yutannihilation left a comment

Choose a reason for hiding this comment

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

Generally looks good. One thing I'm not yet sure is if it's a good idea to stop ensuring show.legend is a logical vector in layer(). Let me think a bit...

Copy link
Member

@yutannihilation yutannihilation left a comment

Choose a reason for hiding this comment

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

if it's a good idea to stop ensuring show.legend is a logical vector in layer().

Now I come to think this PR does better because show.legend can be modified after layer() anyway so it's good to check it right before actually using it.

(A minor downside is that the warning might be shown multiple times but I think it's acceptable.)

@clauswilke
Copy link
Member Author

(A minor downside is that the warning might be shown multiple times but I think it's acceptable.)

That's why I'm overwriting show.legend in the layer after issuing the warning. I think this guarantees that there can be only one warning per layer.

https://github.com/clauswilke/ggplot2/blob/82a7c29b2e18a6b34ac8749d4de59764b9eef52a/R/guides-.r#L372-L373

@yutannihilation
Copy link
Member

Ah, true. Sorry, I don't know why I didn't read the code comment...

@clauswilke clauswilke merged commit 16ed4d0 into tidyverse:master Dec 6, 2019
@clauswilke clauswilke deleted the show.legend branch December 6, 2019 00:59
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.

2 participants