chr_detect: Detect matches in strings

Description Usage Arguments Details Value Examples

Description

Detect matching pattern in character vector.

Usage

1
chr_detect(x, pat, ignore.case = FALSE, ...)

Arguments

x

Character vector

pat

Pattern (regex) to detect from text.

ignore.case

Logical indicating whether to ignore capitalization. Defaults to false.

...

Other named arguments passed to grepl or grep See details for more information.

Details

This is a wrapper around the base R functions grepl and grep. By default, logical values are returned (a la grepl). To return values, include value = TRUE. To return positions, include which = TRUE, pos = TRUE, or position = TRUE.

Value

Logical vector indicating whether each element matched the supplied pattern.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
## return logical vector
chr_detect(letters, "a|b|c|x|y|z")

## return inverted logical values
chr_detect(letters, "a|b|c|x|y|z", invert = TRUE)

## return matching positions
chr_detect(letters, "a|b|c|x|y|z", which = TRUE)

## return inverted matching positions
chr_detect(letters, "a|b|c|x|y|z", which = TRUE, invert = TRUE)

## return matching values
chr_detect(letters, "a|b|c|x|y|z", value = TRUE)

## return inverted matching values
chr_detect(letters, "a|b|c|x|y|z", value = TRUE, invert = TRUE)

mkearney/chr documentation built on May 19, 2019, 3:03 a.m.