grepl_multi: Multiple Pattern Matching

Description Usage Arguments Value Author(s) Examples

Description

grepl_multi is a wrapper for grepl that allows multiple inputs to the pattern argument. Depending on the all argument, it either returns whether each element of x matches all or at least one of the patterns in patterns. grepl_multi inherits all the other parameters of grepl.

Usage

1
2
3
grepl_multi <- function(patterns, x, all = FALSE,
                        ignore.case = FALSE, perl = FALSE,
                        fixed = FALSE, useBytes = FALSE)

Arguments

patterns

A character vector of regular expressions (or strings if fixed == TRUE) to be matched onto x x.

x

A character vector where matches are sought.

all

if TRUE then all values in patterns must match. Otherwise, at least one one match among patterns is required to return TRUE

...

refer to ?grepl for inherited arguments

Value

a logical vector of the same length as x

Author(s)

Sven Halvorson (svenedmail@gmail.com)

Examples

1
2
3
4
5
6
7
8
pat = letters[1:3]
strings = c("foo", "bar", "cabbie", "green chile")

# First we ask, which one of these stings have at least one of "a", "b", or "c"
cbind(strings,grepl_multi(patterns = pat, x = strings))

# Or we can ask, which strings have all three of "a", "b", and "c"
cbind(strings,grepl_multi(patterns = pat, x = strings, all = TRUE))

svenhalvorson/SvenSFPS documentation built on May 21, 2019, 11:42 a.m.