Require usage of direct methods for subsetting strings via regex.Source:
value = TRUE in
grep() returns the subset of the input that matches
the pattern, e.g.
grep("[a-m]", letters, value = TRUE) will return the
first 13 elements (
letters[grep("[a-m]", letters)] and
both return the same thing, but more circuitously and more verbosely.
stringr package also provides an even more readable alternative,
str_subset(), which should be preferred to versions using
x[grep(pattern, x)] and
grep(pattern, x, value = TRUE)
are not completely interchangeable when
x is not character
(most commonly, when
x is a factor), because the output of the
latter will be a character vector while the former remains a factor.
It still may be preferable to refactor such code, as it may be faster
to match the pattern on
levels(x) and use that to subset instead.
linters for a complete list of linters available in lintr.