Description Usage Arguments Value Author(s) References See Also Examples
See generic: copyDirectory
1 2 3 |
from |
|
to |
|
pattern |
|
ensure_to |
|
overwrite |
|
recursive |
|
... |
Further arguments to be passed to subsequent functions/methods. |
logical
. A vector, values correspond to whether or
not each file was successfully copied is invisibly returned.
Janko Thyson janko.thyson@rappster.de
https://github.com/Rappster/filesystr
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | ## Not run:
## Directory preparations //
to <- file.path(tempdir(), "copyDirectory", c("to1", "to2"))
sapply(to, dir.create, recursive=TRUE, showWarnings=FALSE)
## Utility functions //
.carefulCleanup <- function(x, pattern=basename(tempdir()), content.only=TRUE) {
out <- sapply(x, function(ii) {
out <- FALSE
if (grepl(pattern, ii)) {
out <- !as.logical(unlink(ii, recursive=TRUE, force=TRUE))
if (out & content.only) {
dir.create(ii, recursive=TRUE, showWarnings=FALSE)
}
}
out
})
invisible(out)
}
## Open directories in file system browser //
.openRessource(to[1])
.openRessource(to[2])
## One source, one target //
copyDirectory(from = R.home("etc"), to = to[1])
.carefulCleanup(to[1])
## One source, two targets //
copyDirectory(from = R.home("etc"), to = to)
.carefulCleanup(to)
## Two sources, one target //
## Combines content of 'etc' and 'tests'. If there would be any conflicts,
## the would result in an error as 'overwrite = FALSE'.
## Otherwise, existing content is overwritten.
copyDirectory(from = c(R.home("etc"), R.home("tests")), to = to[1])
.carefulCleanup(to)
## Two sources, two targets //
copyDirectory(from = c(R.home("etc"), R.home("tests")), to = to)
.carefulCleanup(to)
## Non-recursive //
## Only files directly below 'from' and actual subdirectories are copied,
## *NOT* their content.
copyDirectory(from = R.home("etc"), to = to[1], recursive = FALSE)
## Subsequent recursive copy, existing content overwritten //
## This will add the actual content of the subdirectories.
copyDirectory(from = R.home("etc"), to = to[1], overwrite = TRUE)
.carefulCleanup(to[1])
## Condition handling //
## Handling of non-existing target directories:
.carefulCleanup(to, content.only = FALSE)
try(copyDirectory(from = R.home("etc"), to = to[1]))
## Existence of target root directories can be ensured:
copyDirectory(from = R.home("etc"), to = to[1], ensure_to =TRUE)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.