Skip to content

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

@heavywatal

Description

@heavywatal

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    false-positivecode that shouldn't lint, but does

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions