which(grepl(pattern, x))
is the same as grep(pattern, x)
, but harder
to read and requires two passes over the vector.
See also
linters for a complete list of linters available in lintr.
Examples
# will produce lints
lint(
text = "which(grepl('^a', x))",
linters = which_grepl_linter()
)
#> <text>:1:1: warning: [which_grepl_linter] grep(pattern, x) is better than which(grepl(pattern, x)).
#> which(grepl('^a', x))
#> ^~~~~~~~~~~~~~~~~~~~~
# okay
lint(
text = "which(grepl('^a', x) | grepl('^b', x))",
linters = which_grepl_linter()
)
#> ℹ No lints found.