Learn R Programming

mark (version 0.8.2)

multi_grepl: Multiple searching

Description

Multiple search pattern searches

Usage

multi_grepl(x, patterns, ..., simplify = TRUE)

multi_grep(x, patterns, ..., simplify = TRUE)

Value

The name or position of the pattern that is matched

Arguments

x

Passed to base::grepl()

patterns

A list or vector of patterns to search across x; if named value returned will be the name of the pattern -- otherwise the position. Pattern match reported will be the first in the list that is found

...

Additional arguments passed to base::grepl()

simplify

if FALSE will return a list of all matches, otherwise the first match found

Examples

Run this code
x <- c("apple", "banana", "lemon")
multi_grepl(x, c("a" = "^[ab]", "b" = "lem"))
multi_grepl(x, c("a" = "^[ab]", "b" = "q"))                   # lemon not matches on either
multi_grepl(x, c("a" = "^[ab]", "b" = "e"))                   # apple matches "a" before "b"
multi_grepl(x, c("a" = "^[ab]", "b" = "e"), simplify = FALSE) # shows all matches
multi_grepl(x, c("^[ab]", "e"))                               # returned as positions
multi_grepl(x, c("^[ab]", "e"), simplify = FALSE)

Run the code above in your browser using DataLab