Learn R Programming

udpipe (version 0.8.11)

txt_grepl: Look up a multiple patterns and indicate their presence in text

Description

A variant of grepl which allows to specify multiple regular expressions and allows to combine the result of these into one logical vector.
You can specify how to combine the results of the regular expressions by specifying an aggregate function like all, any, sum.

Usage

txt_grepl(
  x,
  pattern,
  FUN = all,
  ignore.case = FALSE,
  perl = FALSE,
  fixed = FALSE,
  useBytes = FALSE,
  ...
)

Value

a logical vector with the same length as x with the result of the call to FUN applied elementwise to each result of grepl for each pattern

Arguments

x

a character vector

pattern

a character vector containing one or several regular expressions

FUN

a function to apply to combine the results ot the different regular expressions for each element of x. Defaults to all.

ignore.case

passed on to grepl

perl

passed on to grepl

fixed

passed on to grepl

useBytes

passed on to grepl

...

further arguments passed on to FUN

See Also

Examples

Run this code
x <- c("--A--", "--B--", "--ABC--", "--AC--", "Z")
txt_grepl(x, pattern = c("A", "C"), FUN = all)
txt_grepl(x, pattern = c("A", "C"), FUN = any)
txt_grepl(x, pattern = c("A", "C"), FUN = sum)
data.frame(x = x, 
           A_and_C = txt_grepl(x, pattern = c("A", "C"), FUN = all),
           A_or_C  = txt_grepl(x, pattern = c("A", "C"), FUN = any),
           A_C_n   = txt_grepl(x, pattern = c("A", "C"), FUN = sum))
txt_grepl(x, pattern = "A|C")

Run the code above in your browser using DataLab