filesFindReplace | R Documentation |
This function searches for specified patterns in files within a directory or a given list of files and replaces them with given text. While optimized for R scripts, the function call fileFindReplace function that can work on any text-based files or xlsx Files.
filesFindReplace(
filename,
pattern,
replacement,
word = FALSE,
ignore.case = FALSE,
listonly = FALSE
)
filename |
Character or character vector. The path of the directory, a single file, or a list of files. |
pattern |
Character vector. A vector of patterns to search for in the files. |
replacement |
Character vector. A vector of replacements for the patterns found. |
word |
Logical. If TRUE, only whole words will be replaced. Defaults to FALSE. |
ignore.case |
Logical. If TRUE, the function performs a case-insensitive search. Defaults to FALSE. |
listonly |
Logical. If TRUE, the function only lists the files that would be modified without actually modifying them. Defaults to FALSE. |
The function supports case-sensitive or case-insensitive searches and can either perform the replacements or just list the files that would be modified.
Returns list: names of files assessed = number of changes. The function modifies the files in-place, or lists them if listonly = TRUE
.
fileFindReplace
, xlsxFindReplace
,txtFindReplace
## Not run:
filesFindReplace("path/to/directory", "oldText", "newText")
filesFindReplace("path/to/file.txt", "oldText", "newText")
filesFindReplace(c("file1.txt", "file2.csv"), "oldText", "newText")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.