Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
salim-b opened this issue Jul 20, 2023 · 2 comments · Fixed by #2046
Labels
false-positive code that shouldn't lint, but does

Comments

@salim-b
Copy link
Contributor

salim-b commented Jul 20, 2023

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.

@IndrajeetPatil IndrajeetPatil added the false-positive code that shouldn't lint, but does label Jul 20, 2023
@MichaelChirico
Copy link
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()

@salim-b
Copy link
Contributor Author

salim-b commented Jul 20, 2023

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
Labels
false-positive code that shouldn't lint, but does
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants