Skip to content

styler fails to correctly style syntactic rlang sugar {{ #526

Closed

Description

@ellessenne

Hi!
I noticed that the new {{ }} operator from rlang is not styled properly; for instance, if I style the following lines

library(rlang)
name <- "Jane"
list2({{name}} := 1 + 2)

I get the following:

library(rlang)
name <- "Jane"
list2({
  {
    name
  }
} := 1 + 2)

Not sure what would be a good way of handling this specific operator (maybe @lionel- has an idea), I just thought about reporting it.

Anyway, thanks for styler: absolutely love the package!

Alessandro

Activity

  1. lionel- commented on Jun 27, 2019

    @lionel-
    Member

    We're currently leaning towards foo({{ var }}).

  2. lorenzwalthert commented on Jun 27, 2019

    @lorenzwalthert
    Collaborator

    Thanks guys. Is there a rule in the tidyverse style guide planned? I think we can implement the suggested style from @lionel- without much work. Is {{ space or line break in-sensitive, i.e. does it have the same meaning as { { or {\n{ or does styler currently change the meaning in the example demonstrated by @ellessenne?

  3. ellessenne commented on Jun 28, 2019

    @ellessenne
    Author

    The two examples return the same result:

    library(rlang)
    name <- "Jane"
    
    list2({{name}} := 1 + 2)
    #> $Jane
    #> [1] 3
    
    list2({
      {
        name
      }
    } := 1 + 2)
    #> $Jane
    #> [1] 3

    Created on 2019-06-28 by the reprex package (v0.3.0)

    ...I just think the latter is ugly! 😃 Jokes aside, I think the {{ }} operator should not be broken into multiple lines - otherwise it becomes counter-intuitive?

  4. lorenzwalthert commented on Jun 29, 2019

    @lorenzwalthert
    Collaborator

    I agree that styler's current behavior is not ideal, but I simply asked because if the result would change, the issue would have been much more urgent to fix. We are definitively going to so something about it. I think the consensus is:

    • leave {{ as is.
    • remove spaces after first and third brace.
    • add space after second and before third brace.
    • remove line breaks within.

    For details of the implementation, see #528 or ?set_space_in_curly_curly().

    not sure about {\n{ and similar, but probably it should also be turned into {{ with strict = TRUE in styler::tidyverse_style().

  5. changed the title [-]Issues when styling {{ }} operator of rlang[/-] [+]styler fails to correctly style syntactic rlang sugar {{[/+] on Jun 29, 2019
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