multi_grepl: Multiple searching

Description Usage Arguments Value Examples

View source: R/searches.R

Description

Multiple search pattern searches

Usage

1
2
3
multi_grepl(x, patterns, ..., simplify = TRUE)

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

Arguments

x

a character vector where matches are sought, or an object which can be coerced by as.character to a character vector. Long vectors are supported.

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

Value

The name or position of the pattern that is matched

Examples

1
2
3
4
5
6
7
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)

mark documentation built on July 16, 2021, 9:07 a.m.