Skip to content

unnecessary_concatenation_linter wrongly complains about usage with magrittr's assignment pipe operator %<>% #2008

Closed

Description

@salim-b

Consider the following reprex:

tmp_file <- tempfile(fileext = "R")
writeLines(con = tmp_file,
           text = "
library(magrittr)
x <- 1:2
x %<>% c(3)
x
")

lintr::lint(filename = tmp_file,
            linters = list(lintr::unnecessary_concatenation_linter()))
#> /tmp/RtmpyaBMnL/filee0674c13fd78R:4:8: style: [unnecessary_concatenation_linter] Unneeded concatenation of a constant. Remove the "c" call.
#> x %<>% c(3)
#>        ^~~~

Created on 2023-07-20 with reprex v2.0.2

x %<>% c(3) above is the magrittr way to write x <- c(x, 3), so lintr should ideally allow c() with a single constant if it is preceded by the %<>% operator.

Activity

  1. added
    false-positive
    on Jul 20, 2023
  2. MichaelChirico commented on Jul 20, 2023

    @MichaelChirico
    Collaborator

    Thanks Salim. I'm not exactly sure how to proceed.

    On the one hand, the assignment pipe is not allowed by the Tidyverse guide:

    https://style.tidyverse.org/pipes.html#assignment-2

    on the other hand, that's kind of independent of the concatenation linter.

    Probably we should:

    1. lint this with assignment_linter()
    2. not lint it with unnecessary_concatenation_linter()
  3. salim-b commented on Jul 20, 2023

    @salim-b
    ContributorAuthor

    I know the TSG instructs to avoid this operator, but I still ike to use it. Thus I very much agree with your second action point.

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

    false-positive

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions