Skip to content

Enforce line break after + in ggplot2 #544

Closed

Description

@mine-cetinkaya-rundel

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?

Activity

  1. lorenzwalthert commented on Sep 17, 2019

    @lorenzwalthert
    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.

  2. lorenzwalthert commented on Sep 17, 2019

    @lorenzwalthert
    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.

  3. mine-cetinkaya-rundel commented on Oct 16, 2019

    @mine-cetinkaya-rundel
    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.

  4. lorenzwalthert commented on Dec 14, 2019

    @lorenzwalthert
    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?

  5. added a commit that references this issue on Dec 18, 2019
  6. vimaloctavius commented on Sep 1, 2020

    @vimaloctavius

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

  7. lorenzwalthert commented on Sep 1, 2020

    @lorenzwalthert
    Collaborator

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

  8. vimaloctavius commented on Sep 2, 2020

    @vimaloctavius

    @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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions