gsubr: Recursive gsub

Description Usage Arguments Value Examples

View source: R/gsubr.R

Description

Recursive call to gsub in R

Usage

1
gsubr(pattern, replacement, path, recursive = FALSE, test = TRUE, ...)

Arguments

pattern

character, string containing a regular expression

replacement

character, replacement pattern

path

character, path to search, see details

recursive

logical, Should the listing recurse into directories? passed to list.files, Default: FALSE

test

logical, Should the gsub be tested to console or replace on disk, Default: TRUE

...

arguments passed to gsub

Value

character

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
dir.create(file.path(tempdir(), 'gsubr/d'),recursive = TRUE)

path_up <- tempfile(pattern = 'gsubr-', 
fileext = '.txt', 
tmpdir = file.path(tempdir(), 'gsubr'))

path_down <- tempfile(pattern = 'gsubr-', 
fileext = '.txt', 
tmpdir = file.path(tempdir(), 'gsubr/d'))

cat('this is a test',sep='\n',file = path_up)

cat('this is a test in the subdir',sep='\n',file = path_down)

list.files(tempdir(),recursive = TRUE)

gsubr(pattern = '\\bis\\b', 
replacement = 'was', 
path = tempdir(),
recursive = TRUE)

gsubr(pattern = '\\bis\\b', 
replacement = 'was', 
path = tempdir(),
recursive = TRUE,
test = FALSE)

readLines(path_up)
readLines(path_down)

unlink(file.path(tempdir(),'gsubr'),recursive = TRUE)

yonicd/vcs documentation built on July 20, 2020, 8:43 a.m.