Skip to content

infix operators don't conform to tidyverse standards #302

Closed

Description

@nathaneastwood

I have found a difference between lintr and styler. styler will correct the following

(10 ^ (x - 1)) + 1

to

(10^(x - 1)) + 1

This gives the following lintr errors:

Put spaces around all infix operators.
Place a space before left parenthesis, except in a function call.

Looking at the current tidyverse style guide, styler is correct here. To get around this you can use

styler::style_pkg(".", math_token_spacing = list(one = c("'^'", "'+'", "'-'", "'*'", "'/'")))

A similar issue exists with

break ()

which gets corrected to

break()

by styler. I am not sure which is correct with regards to the tidyverse here.

Activity

  1. jimhester commented on Mar 12, 2018

    @jimhester
    Member

    The ^ behavior is a bug, PR are welcome.

    break is a statement, not a function call, so you should not have () in your code at all in this case.

  2. added a commit that references this issue on Mar 12, 2018
    3a26dc7
  3. tvatter commented on Mar 28, 2019

    @tvatter

    Quick question: I noticed that this fix is not present on the CRAN version, which is around 6 months more recent than the fix itself. Any idea what happened?

  4. bersbersbers commented on Jul 20, 2020

    @bersbersbers

    Hello, I believe this is still an issue:

    x^(y + z)
    

    lintr_2.0.1 still says

    Place a space before left parenthesis, except in a function call.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions