str_replace_file | R Documentation |
Applies pattern-based string replacements to one or more files. Expects a series of regular-expression-replacement pairs that are applied one-by-one in the
given order. By default, all performed replacements are displayed on the console (verbose = TRUE
) without actually changing any file content
(run_dry = TRUE
).
str_replace_file(
path,
pattern,
process_line_by_line = FALSE,
eol = c("LF", "CRLF", "CR", "LFCR"),
verbose = TRUE,
n_context_chrs = 20L,
show_rel_path = TRUE,
run_dry = TRUE
)
path |
Paths to the text files. A character vector. |
pattern |
A named character vector with patterns as names and replacements as values ( |
process_line_by_line |
Whether each line in a file should be treated as a separate string or the whole file as one single string. While the latter is
more performant, you probably want the former if you're using |
eol |
End of line (EOL) control character sequence. Only relevant if
|
verbose |
Whether or not to display replacements on the console. |
n_context_chrs |
The (maximum) number of characters displayed around the actual |
show_rel_path |
Whether or not to display file |
run_dry |
Whether or not to show replacements on the console only, without actually modifying any files. Implies |
Note that process_line_by_line
requires the line ending standard (EOL) of the input files to be correctly set via
eol
. It always defaults to "LF"
(Unix standard) since this is something which cannot be reliably detected without complex heuristics (and even then
not unambiguously in all edge cases). Simply deriving a default depending on the host OS (i.a. "LF"
on Unix systems like Linux and macOS and "CRLF"
on
Windows) seems like a really bad idea with regard to cross-system collaboration (files shared via Git etc.), thus it was refrained from.
The text files are assumed to be in UTF-8 character encoding, other encodings are not supported.
path
invisibly.
Other string functions:
str_normalize()
,
str_normalize_file()
,
str_replace_verbose()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.