str_detect2 {tidyplus} | R Documentation |
Detect the presence/absence of a match
Description
Vectorised over string
and pattern
.
Actually equivalent to grepl(pattern, x)
as returns FALSE
for NA
s (unlike stringr::str_detect()
).
This behavior is useful when searching comments many of which are NA to
indicate no comments present.
Usage
str_detect2(string, pattern, negate = FALSE)
Arguments
string |
Input vector. Either a character vector, or something coercible to one. |
pattern |
Pattern to look for. The default interpretation is a regular expression, as described in
Match a fixed string (i.e. by comparing only bytes), using
Match character, word, line and sentence boundaries with
|
negate |
If |
Value
A logical vector the same length as string
/pattern
.
See Also
grepl()
and stringr::str_detect()
Examples
x <- c("b", NA, "ab")
pattern <- "^a"
grepl(pattern, x)
stringr::str_detect(x, pattern)
str_detect2(x, pattern)