ac_replace_file() replaces all non-overlapping matches in input files and
writes the result to output files.
Arguments
- ac
An
<ac_automaton>object created byac_build().- path
A vector of input file paths 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.- output
A vector of output file paths. It must have the same length as
path. IfNULL, output paths are created by adding"_replaced"suffix. Existing output files are overwritten.- stream
If
FALSE(default), each file is read into memory before replacement. IfTRUE, files are searched and replaced as streams. Stream replacement requires an automaton built withmatch_kind = "standard".
Examples
ac <- ac_build(c("fox", "brown", "quick"))
path <- tempfile(fileext = ".txt")
writeLines("The quick brown fox.", path)
ac_replace_file(path = path, ac = ac, replace_with = c("sloth", "grey", "slow"))
#> [1] "/tmp/RtmpuF2ITV/file1d3a3acd5a2c_replaced.txt"