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 byac_build().- doc
A character vector of documents to search.
- na
How to handle
NAdocuments."keep"returnsNA(default);"false"treats missing documents as not matched;"error"fails.
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