Skip to contents

which(grepl(pattern, x)) is the same as grep(pattern, x), but harder to read and requires two passes over the vector.

Usage

which_grepl_linter()

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.