copyDirectory-character-character-missing-method: Copy Directory/Directories

Description Usage Arguments Value Author(s) References See Also Examples

Description

See generic: copyDirectory

Usage

1
2
3
## S4 method for signature 'character,character,missing'
copyDirectory(from, to, pattern,
  ensure_to = FALSE, overwrite = FALSE, recursive = TRUE, ...)

Arguments

from

character. Source directory.

to

character. Target directory.

pattern

character. Filter for matching specific directory content.

ensure_to

logical. Dimension: 1. TRUE means non-existing target directories in to are created, FALSE means they will trigger an error.

overwrite

logical. Overwrite existing directory (TRUE) or not (FALSE, default).

recursive

logical. Copy subdirectories and their content (TRUE) or not (FALSE).

...

Further arguments to be passed to subsequent functions/methods.

Value

logical. A vector, values correspond to whether or not each file was successfully copied is invisibly returned.

Author(s)

Janko Thyson janko.thyson@rappster.de

References

https://github.com/Rappster/filesystr

See Also

copyDirectory

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
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)

rappster/filesystr documentation built on May 26, 2019, 11:17 p.m.