Learn R Programming

lintr (version 3.2.0)

which_grepl_linter: Require usage of grep over which(grepl(.))

Description

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()

Arguments

Tags

consistency, efficiency, readability, regex

See Also

linters for a complete list of linters available in lintr.

Examples

Run this code
# will produce lints
lint(
  text = "which(grepl('^a', x))",
  linters = which_grepl_linter()
)

# okay
lint(
  text = "which(grepl('^a', x) | grepl('^b', x))",
  linters = which_grepl_linter()
)

Run the code above in your browser using DataLab