gsub_file {xfun} | R Documentation |
These functions provide the "file" version of gsub()
, i.e.,
they perform searching and replacement in files via gsub()
.
gsub_file(file, ...) gsub_files(files, ...) gsub_dir(..., dir = ".", recursive = TRUE, ext = NULL, mimetype = ".*", rw_error = TRUE) gsub_ext(ext, ..., dir = ".", recursive = TRUE)
file |
Path of a single file. |
... |
Arguments passed to |
files |
A vector of file paths. |
dir |
Path to a directory (all files under this directory will be replaced). |
recursive |
Whether to find files recursively under a directory. |
ext |
A vector of filename extensions (without the leading periods). |
mimetype |
A regular expression to filter files based on their MIME
types, e.g., |
rw_error |
Whether to signal an error if a certain file cannot be read
or written. If |
These functions perform in-place replacement, i.e., the files will be overwritten. Make sure you backup your files in advance, or use version control!
library(xfun) f = tempfile() writeLines(c("hello", "world"), f) gsub_file(f, "world", "woRld", fixed = TRUE) readLines(f)