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. Coerced to character.

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 text. Determines the output. See section Value.

na.replace

A single value to replace each NA with in the result.

use.which

A logical value. TRUE to convert result with which. Only if output is.atomic, otherwise ignored. Deprecated.

cores

Numeric value for how many cores to use for computation using mclapply.

...

Further arguments passed to functions grepl.

Value

Depending on the function defined with log.fun, the return value is either

Author(s)

Sven E. Templer

See Also

grepl, mclapply

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)

#

[Package miscset version 1.1.0 Index]