mgrepl {miscset} | R Documentation |
Multiple Pattern Matching and Replacement
Description
mgrepl
allows multiple patterns search in character vectors,
offering multicore support to parallelize search over all patterns
using mclapply.
Usage
mgrepl(patterns, text, log.fun = all, na.replace = FALSE,
use.which = FALSE, cores = 1, ...)
Arguments
patterns |
A vector or list containing regular expressions
(regex) to be searched in |
text |
Character vector on which the search is performed. |
log.fun |
A function to apply on the result of matching each pattern
on each element of |
na.replace |
A single value to replace each |
use.which |
A logical value.
|
cores |
Numeric value for how many cores to use for computation using
|
... |
Further arguments passed to functions grepl. |
Value
Depending on the function defined with log.fun
, the return value is either
a
matrix
is obtained with e.g. identity or as.integer. Each row holds the result of a single pattern.a
list
is returned for functions which create results of different lengths for each element, such as which.
Author(s)
Sven E. Templer
See Also
Examples
#
# strings
s <- c("ab","ac","bc", NA)
# match all patterns (default)
mgrepl(c("a", "b"), s)
# match any of the patterns
mgrepl(c("a", "b"), s, any)
grepl("a|b", s)
# return logical matrix, one column for each pattern
mgrepl(c("a", "b"), s, identity)
# return count of matches
mgrepl(c("a", "b"), s, sum)
#