Open MichaelChirico opened 4 years ago
Can you check if this issue occurs in the master branch? I can't reproduce with that.
Same for me on current master. sessionInfo()
in details:
How should the warning message be worded here?
Avoid expressions of the form `object[1:xxx, ]`
Avoid expressions of the form `[1:min(8, nrow(mtcars)), ]`
Avoid using the range operator when subsetting.
... alternatives ...
I think something like the 3rd one is closest to best. I might say
Mixing
:
withnrow
is risky because it is prone to errors whennrow
is 0.
I like your suggestion, but would leave out the "is risky" part.
Mixing
:
withnrow
is prone to errors whennrow
is 0.
Just updating the reprex with the current status of this linter:
library(lintr)
lint(
text = "mtcars[1:min(8, nrow(mtcars)), ]",
linters = seq_linter()
)
#> <text>:1:8: warning: [seq_linter] 1:min(...) is likely to be wrong in the empty edge case. Use seq_len(min(...)) instead.
#> mtcars[1:min(8, nrow(mtcars)), ]
#> ^~~~~~~~~~~~~~~~~~~~~~
Created on 2022-07-29 by the reprex package (v2.0.1.9000)
I think this is incorrect because
! min %in% bad_funcs
, i.e. it's not the1:min
that's triggering the lint, it's the use ofnrow
in1:
.