Skip to contents

ac_detect() returns whether each document has at least one pattern match.

Usage

ac_detect(ac, doc, ..., na = c("keep", "false", "error"))

Arguments

ac

An <ac_automaton> object created by ac_build().

doc

A character vector of documents to search.

...

Must be empty. This is used to require optional arguments to be supplied by name.

na

How to handle NA documents. "keep" returns NA (default); "false" treats missing documents as not matched; "error" fails.

Value

A logical vector with the same length as doc.

Examples

if (requireNamespace("dplyr", quietly = TRUE)) {
  ac <- ac_build(c("hello", "world"))
  docs <- data.frame(doc = c("hello world", "nothing", "world"))
  dplyr::mutate(docs, matched = ac_detect(ac, doc))
}
#>           doc matched
#> 1 hello world    TRUE
#> 2     nothing   FALSE
#> 3       world    TRUE