Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

txt_contains

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 x, a vector of these or a list of pattern elements where the list elements include and exclude indicate to find a pattern in x while excluding elements which have another pattern

value

logical, indicating to return the elements of x where the pattern was found or just a logical vector. Defaults to FALSE indicating to return a logical.

ignore.case

logical, if set to FALSE, the pattern matching is case sensitive and if TRUE, case is ignored during matching. Passed on to grepl

...

other parameters which can be passed on to grepl e.g. fixed/perl/useBytes

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")

udpipe

Tokenization, Parts of Speech Tagging, Lemmatization and Dependency Parsing with the 'UDPipe' 'NLP' Toolkit

v0.8.5
MPL-2.0
Authors
Jan Wijffels [aut, cre, cph], BNOSAC [cph], Institute of Formal and Applied Linguistics, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic [cph], Milan Straka [ctb, cph], Jana Straková [ctb, cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.