Skip to content

sort_linter suggests wrong code when x[order(...)] takes multiple vectors #2156

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

Closed
heavywatal opened this issue Sep 13, 2023 · 1 comment · Fixed by #2157
Closed

sort_linter suggests wrong code when x[order(...)] takes multiple vectors #2156

heavywatal opened this issue Sep 13, 2023 · 1 comment · Fixed by #2157
Labels
false-positive code that shouldn't lint, but does
Milestone

Comments

@heavywatal
Copy link

Here is a reprex:

lintr::lint(linters = list(lintr::sort_linter()), text = "
x = c(1, 2, 3, 4)
y = c(NA, 10, 20, NA)
x[order(y, x)]
")
#> <text>:4:3: warning: [sort_linter] sort(y, na.last = TRUE) is better than y[order(y, x)].
#> x[order(y, x)]
#>   ^~~~~~~~~~~

Obviously sort(y, na.last = TRUE) does not generate what x[order(y, x)] does.

x = c(1, 2, 3, 4)
y = c(NA, 10, 20, NA)
x[order(y, x)]
#> [1] 2 3 1 4
sort(y, na.last = TRUE)
#> [1] 10 20 NA NA
@MichaelChirico MichaelChirico added this to the 3.1.1 milestone Sep 13, 2023
@MichaelChirico MichaelChirico added the false-positive code that shouldn't lint, but does label Sep 13, 2023
@heavywatal
Copy link
Author

Thank you, @MichaelChirico, for the quick response as always!

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.

2 participants