Learn R Programming

fritools (version 4.6.0)

runsed: Replace a Pattern in Files with a Replacement String

Description

This function mimics the runsed script published in Unix Power Tools.

Usage

runsed(files, pattern, replacement)

Value

Invisibly the vector of names of files changed.

Arguments

files

A list of file names in which to replace.

pattern

A regex pattern, see gsub.

replacement

A string, see gsub.

References

Shelley Powers, Jerry Peek, Tim O'Reilly and Mike Loukides, 2002, Unix Power Tools, 3rd edition, O'Reilly Media, Inc.

See Also

Other file utilities: clipboard_path(), delete_trailing_blank_lines(), delete_trailing_whitespace(), develop_test(), file_copy(), file_modified_last(), file_save(), file_string(), find_files(), get_lines_between_tags(), get_mtime(), get_unique_string(), grep_file(), is_files_current(), is_path(), paths, search_files(), split_code_file(), touch()

Other searching functions: compare_vectors(), file_modified_last(), find_files(), fromto(), grep_file(), missing_docs, search_files(), search_rows(), summary.filesearch()

Examples

Run this code
source_files <- list.files(system.file(package = "fritools", "source", "R"),
                           pattern = ".*\\.R$", full.names = TRUE)
file.copy(source_files, tempdir(), overwrite = TRUE)
files <- find_files(file_names = file.path(tempdir(),
                                           basename(source_files)))
print(f <- runsed(files, pattern = "_clean", replacement = "_cleanr"))
print(f <- runsed(files, pattern = "_cleanr\\>", replacement = "_cleaner"))

Run the code above in your browser using DataLab