Description Usage Arguments Details Value See Also Examples
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)
.
1 2 3 | str_exclude(string, pattern)
str_which_not(string, pattern)
|
string |
a input vector that is coercible to a character vector. |
pattern |
pattern to look for and exclude. |
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.
a character or integer vector for str_exclude
and str_which_not
,
respectively.
base::grep()
with argument invert = TRUE
and value = TRUE
and
stringr::str_detect()
for the function it wraps and for the underlying
implementation.
1 2 3 | fruits <- c("apple", "avocado", "banana")
str_exclude(fruits, "ap")
str_which_not(fruits, "^a")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.