Strongly typed wrappers around grep that have the
value (see note), ignore.case and fixed arguments
set internally (as well as the conflicting arguments).
If grepv is found in the current R version, it is
reexported from base.
Usage
grepv(
pattern,
x,
ignore.case = FALSE,
perl = FALSE,
value = TRUE,
fixed = FALSE,
useBytes = FALSE,
invert = FALSE
)
grepvf(pattern, x, useBytes = FALSE, invert = FALSE)
grepvi(pattern, x, perl = FALSE, useBytes = FALSE, invert = FALSE)Arguments
- pattern
character string containing a regular expression (or character string for
fixed = TRUEto be matched in the given character vector. Coerced by as.character to a character string if possible. If a character vector of length2or more is supplied, the first element is used with a warning. Missing values are allowed.- x
a character vector where matches are sought, or an object which can be coerced by as.character to a character vector. Long vectors are supported.
- ignore.case
logical. if
FALSE, the pattern matching is case sensitive and ifTRUE, case is ignored during matching.- perl
logical. Should Perl-compatible regexps be used?
- value
logical. If
FALSE, a vector containing the (integer) indices of the matches determined by grep is returned, and ifTRUE, a vector containing the matching elements themselves is returned.- fixed
logical. If
TRUE, pattern is a string to be matched as is. Overrides all conflicting arguments.- useBytes
logical. If
TRUEthe matching is done byte-by-byte rather than character-by-character.- invert
logical. If
TRUEreturn indices or values for elements that do not match.
Value
character vector containing the selected elements of x
(after coercion, preserving names but no other attributes).
grepv() can also return a vector of the indices of the
elements of x that yielded a match (or not, for
invert = TRUE) if value = FALSE (see note). This will
be an integer vector unless the input is a long vector,
when it will be a double vector.
Details
*f() suffixed functions have fixed = TRUE and conflicting
arguments (perl and ignore.case) set as FALSE.
*i() suffixed functions have ignore.case = TRUE and the
conflicting fixed argument set as FALSE.
For full documentation of the wrapped functions, see the help
pages for grep.
Note
suppr wrappers of the base grep/sub functions remove the
arguments that relate to the strong typing, just like
grepl does by not having a value argument. However,
the base grepv implementation has kept the value
argument, so the version here keeps the value argument
for compatibility.
See also
Other pattern-match-replacement-wrappers:
grep-wrappers,
grepl-wrappers,
sub-wrappers
