ac_replace() replaces all non-overlapping matches in each document with
the corresponding replacement string.
Usage
ac_replace(ac, doc, replace_with, na = c("keep", "empty", "error"))Arguments
- ac
An
<ac_automaton>object created byac_build().- doc
A character vector of documents to search and replace.
- replace_with
A character vector of replacements. If length 1, the same replacement is used for every pattern. Otherwise, it MUST have the same length as
ac_patterns(ac), and replacements are matched to patterns by position.- na
How to handle
NAdocuments."keep"returnsNA_character_(default);"empty"treats missing documents as empty strings;"error"fails.
Examples
ac <- ac_build(c("fox", "brown", "quick"))
ac_replace(
ac,
"The quick brown fox.",
c("sloth", "grey", "slow")
)
#> [1] "The slow grey sloth."
ac <- ac_build(c("append", "appendage", "app"), match_kind = "leftmost_first")
ac_replace(ac, "append the app to the appendage", c("x", "y", "z"))
#> [1] "x the z to the xage"