Learn R Programming

miscset (version 1.0.0)

mgrepl: Multiple Pattern Matching and Replacement

Description

mgrepl searches for any or all patterns and returns logical values. Combination of the results is done via the logic functions any, all or identity, for example. Multicore feature is made available by parallel::mclapply.

Usage

mgrepl(patterns, text, log.fun = any, use.which = FALSE, cores = 1, ...)

Arguments

patterns
A character vector containing a regular expression (regex) to be searched in text.
text
Character vector where the search and replace is performed.
log.fun
Logical function (any or all) to evaluate occurence of each pattern in patterns in each value of text. Can also be custom. See examples.
use.which
Logical, TRUE to return an integer like which instead a logical vector.
cores
Numeric value for how many cores to use for computation using mclapply.
...
Further arguments passed to functions grepl(), sub() and gsub().

Value

Logical vector of sam length as text where TRUE means either any or all patterns in patternlist are matched in text depending on log.fun. Using identity as logical returns a matrix with results of patterns per row.

See Also

grep, mclapply

Examples

Run this code
#

# Compare different "log.fun" parameters:
mgrepl(c("a","b"), c("ab","ac","bc"), any)
mgrepl(c("a","b"), c("ab","ac","bc"), all)
mgrepl(c("a","b"), c("ab","ac","bc"), all, use.which = TRUE)
mgrepl(c("a","b"), c("ab","ac","bc"), identity)
mgrepl(letters[1:3], c("ax","xab","xbc"), function (x) sum(x)>1)

#

Run the code above in your browser using DataLab