betterGrepl: Better grepl

Description Usage Arguments Value Examples

View source: R/betterGrepl.R

Description

This function behaves similarly to grepl, except that an NA pattern or NA element of x returns FALSE, but NA matched to NA returns TRUE

Usage

1
betterGrepl(pattern, x, ignore.case = T, fixed = T)

Arguments

pattern

character string containing a regular expression (or character string for fixed = TRUE) to be matched in the given character vector. Coerced by as.character to a character string if possible. If a character vector of length 2 or more is supplied, the first element is used with a warning.

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.

ignore.case

logical. if FALSE, the pattern matching is case sensitive and if TRUE, case is ignored during matching.

fixed

logical. If TRUE, pattern is a string to be matched as is. Overrides all conflicting arguments.

Value

Logical vector of the same length as x indicating which elements had matches

Examples

1
2
3
4
5
6
7
x = c("Alpha", "Beta", "Bet", NA_character_, "B")
betterGrepl(pattern = "a", x)
betterGrepl(pattern = NA_character_, x)
betterGrepl(pattern = NA_character_, x, ignore.case = F)
betterGrepl("Beta", x)
betterGrepl("B", x)
betterGrepl("X", x)

debarros/dbTools documentation built on Sept. 18, 2020, 10:51 a.m.