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

Enforce line break after + in ggplot2 #544

Closed
mine-cetinkaya-rundel opened this issue Sep 17, 2019 · 7 comments · Fixed by #569
Closed

Enforce line break after + in ggplot2 #544

mine-cetinkaya-rundel opened this issue Sep 17, 2019 · 7 comments · Fixed by #569

Comments

@mine-cetinkaya-rundel
Copy link

mine-cetinkaya-rundel commented Sep 17, 2019

I'd love to see styler::tidyverse_style() enforce a line break after + in ggplot2 code, i.e.

ggplot(data = mtcars, mapping = aes(x = mpg, y = vs)) + geom_point()

should be

ggplot(data = mtcars, mapping = aes(x = mpg, y = vs)) + 
  geom_point()

Is this a feasible feature to implement?

@lorenzwalthert
Copy link
Collaborator

Can you point me to an existing rule in the tidyverse style guide that requires such a behavior? We generally only implement rules explicitly formulated there. Also, styler currently does not understand which namespace a token belongs to, i.e. it could not distinguish + from ggplot2 and the base +. Related issue: #247.

@lorenzwalthert
Copy link
Collaborator

One thing you could do is to adapt the tidyverse style guide and add line breaks after + when the token afterwards is a function call, which would avoid generating line breaks for simple arithmetic operations like 1 + 1.

@mine-cetinkaya-rundel
Copy link
Author

@lorenzwalthert As a reference, the advice around line breaks for ggplot2 are now in the style guide as well: https://style.tidyverse.org/ggplot2.html.

@lorenzwalthert
Copy link
Collaborator

I am a bit surprised to be honest that Hadley has accepted style advise that is so specific to a package in the style guide 😄. Anyways I think we might derive more general rules for arithmetic
operations that involve function call. For now, I implemented what you suggested. Can you have a look at the test files in #569 I added (called ggplot2-in.R for before and ggplot2-out.R for after) and tell me if these tests look reasonable? Also, I'd like you to install that version of styler with

remotes::install_github("r-lib/styler@569")

and style your files with it and tell me if the result is satisfying. Can you do that?

@vimaloctavius
Copy link

Would love to see this feature added, easier to manage typing when using notebooks

@lorenzwalthert
Copy link
Collaborator

@vimal739 This feature is available in the latest CRAN release and any CRAN release after December 18, 2019.

@vimaloctavius
Copy link

@lorenzwalthert Wow that's great, thanks much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants