str_exclude: Exclude strings matching a pattern, or find positions.

Description Usage Arguments Details Value See Also Examples

View source: R/str_exclude.R

Description

str_exclude() is a wrapper function (much like stringr::str_subset) around x[!str_detect(x, pattern)], and is equivalent to grep(pattern, x, value = TRUE, invert = TRUE). str_which_not() is a wrapper around which(str_detect(x, pattern)), and is equivalent to grep(pattern, x, invert = TRUE).

Usage

1
2
3

Arguments

string

a input vector that is coercible to a character vector.

pattern

pattern to look for and exclude.

Details

If the stringr package is installed it is vectorized over string and pattern. Otherwise base::grep() is used which is not vectorized over pattern and only the first element is used.

As of stringr >= 1.4.0 the function stringr::str_subset() gained a negate argument, rendering this function obsolete, unnecessary and convoluted. Well there you are - c'est la vie.

Value

a character or integer vector for str_exclude and str_which_not, respectively.

See Also

base::grep() with argument invert = TRUE and value = TRUE and stringr::str_detect() for the function it wraps and for the underlying implementation.

Examples

1
2
3
fruits <- c("apple", "avocado", "banana")
str_exclude(fruits, "ap")
str_which_not(fruits, "^a")

tstev/tstevR documentation built on May 18, 2020, 10:57 p.m.