Skip to content

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

Closed
@salim-b

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    false-positivecode that shouldn't lint, but does

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions