Description Usage Arguments Value Examples
Recursive call to gsub in R
1 |
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 |
character
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.