Debian Codegraph @

man/gsub_file.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/io.R
3 \name{gsub_file}
4 \alias{gsub_file}
5 \alias{gsub_files}
6 \alias{gsub_dir}
7 \alias{gsub_ext}
8 \title{Search and replace strings in files}
9 \usage{
10 gsub_file(file, ..., rw_error = TRUE)
11
12 gsub_files(files, ...)
13
14 gsub_dir(..., dir = ".", recursive = TRUE, ext = NULL, mimetype = ".*")
15
16 gsub_ext(ext, ..., dir = ".", recursive = TRUE)
17 }
18 \arguments{
19 \item{file}{Path of a single file.}
20
21 \item{...}{For \code{gsub_file()}, arguments passed to \code{gsub()}. For
22 other functions, arguments passed to \code{gsub_file()}. Note that the
23 argument \code{x} of \code{gsub()} is the content of the file.}
24
25 \item{rw_error}{Whether to signal an error if the file cannot be read or
26 written. If \code{FALSE}, the file will be ignored (with a warning).}
27
28 \item{files}{A vector of file paths.}
29
30 \item{dir}{Path to a directory (all files under this directory will be
31 replaced).}
32
33 \item{recursive}{Whether to find files recursively under a directory.}
34
35 \item{ext}{A vector of filename extensions (without the leading periods).}
36
37 \item{mimetype}{A regular expression to filter files based on their MIME
38 types, e.g., \code{'^text/'} for plain text files.}
39 }
40 \description{
41 These functions provide the "file" version of \code{\link[=gsub]{gsub()}}, i.e.,
42 they perform searching and replacement in files via \code{gsub()}.
43 }
44 \note{
45 These functions perform in-place replacement, i.e., the files will be
46 overwritten. Make sure you backup your files in advance, or use version
47 control!
48 }
49 \examples{
50 library(xfun)
51 f = tempfile()
52 writeLines(c("hello", "world"), f)
53 gsub_file(f, "world", "woRld", fixed = TRUE)
54 readLines(f)
55 }