sed_replace: Replace a matched regular expression pattern across multiple...

View source: R/sed_replace.R

sed_replaceR Documentation

Replace a matched regular expression pattern across multiple files

Description

Search and replace a regex pattern across several files. This only works on POSIX compatible systems where sed is available. It is recommended to use this feature only on files checked into a version control system like git.

Usage

sed_replace(
  pattern,
  replace,
  dir = ".",
  case_sensitive = TRUE,
  path_pattern = getOption("sifr.path_pattern"),
  path_case_sensitive = FALSE,
  recursive = TRUE
)

Arguments

pattern

character scalar. A sed compatible regular expression pattern for which to search in files.

replace

character scalar.

dir

character scalar. A file system path to the directory in which files should be search.

case_sensitive

logical scalar. If TRUE pattern is matched case sensitively. Please not that this is not supported on BSD platforms such as macOS. See this Stack Overflow post.

path_pattern

character scalar. A regular expression pattern to match file paths against. Defaults to common source files for R (.R, .Rmd, Rnw, Rhtml, c, cpp). Please note that .Rd files are not included by default. You can modify the default behavior by setting the option() sifr.path_pattern.

path_case_sensitive

logical. If TRUE path_pattern is matched case sensitively.

recursive

logical scalar. If TRUE files are searched recursively starting from dir.

Value

A sif_result data.table that contains all matched lines (before replacement took place)

Notes

sed has its own flavor of regular expression that does not support all features. The exact features supported are platform dependent (e.g. case insensitive matching is not supported on macOS).

Side Effects

Replaces text that matches pattern across all files that match path_pattern with replace.


s-fleck/sifr documentation built on Oct. 15, 2023, 5:04 a.m.