which_grepl
NoteAdded in 0.0.8
What it does
Checks for usage of which(grepl(...)) and replaces it with grep(...).
Why is this bad?
which(grepl(...)) is harder to read and is less efficient than grep() since it requires two passes on the vector.
This rule has an automatic fix for direct calls and for pipe chains where the piped value can be unambiguously assigned to grepl()’s pattern or x argument.
Example
x <- c("hello", "there")
which(grepl("hell", x))
which(grepl("foo", x))Use instead:
x <- c("hello", "there")
grep("hell", x)
grep("foo", x)References
See ?grep