txt_contains {udpipe} | R Documentation |
Check if text contains a certain pattern
Description
Look up text which has a certain pattern. This pattern lookup is performed by executing a regular expression using grepl
.
Usage
txt_contains(x, patterns, value = FALSE, ignore.case = TRUE, ...)
Arguments
x |
a character vector with text |
patterns |
a regular expression which might be contained in |
value |
logical, indicating to return the elements of |
ignore.case |
logical, if set to |
... |
other parameters which can be passed on to |
Value
a logical vector of the same length as x
indicating if one of the patterns was found in x
.
Or the vector of elements of x
where the pattern was found in case argument value
is set to TRUE
See Also
Examples
x <- c("The cats are eating catfood",
"Our cat is eating the catfood",
"the dog eats catfood, he likes it",
NA)
txt_contains(x, patterns = c("cat", "dog"))
txt_contains(x, patterns = c("cat", "dog"), value = TRUE)
txt_contains(x, patterns = c("eats"), value = TRUE)
txt_contains(x, patterns = c("^The"), ignore.case = FALSE, value = TRUE)
txt_contains(x, patterns = list(include = c("cat"), exclude = c("dog")),
value = TRUE)
txt_contains(x, "cat") & txt_contains(x, "dog")