multi_grepl: Multiple searching

View source: R/searches.R

multi_greplR Documentation

Multiple searching

Description

Multiple search pattern searches

Usage

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

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

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

Value

The name or position of the pattern that is matched

Examples

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 May 29, 2024, 5:13 a.m.