decomposePath-character-method: Decompose Path

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

Description

See generic: decomposePath.

Usage

1
2
3
## S4 method for signature 'character'
decomposePath(path = ".", dir_slash = FALSE,
  shortform = FALSE, ...)

Arguments

path

character. Vector of file paths. Default: files in current directory.

dir_slash

logical. Are directory paths denoted by a trailing slash (TRUE) or not (FALSE, default). See details.

shortform

logical. Dimension: 1. Use shortforms (TRUE) for getwd() (i.e. ".", dirname(getwd() (i.e. ".." and HOME (i.e. "~") or not (FALSE, default).

...

Further arguments passed to: standardizePath

Value

character matrix with three columns named "dirname", "filename" and "extension". strip_extension returns a character vector of the second column, and get_extension returns a character vector of the third column. recompose_path returns a character vector of paths.

Author(s)

Janko Thyson janko.thyson@rappster.de

References

https://github.com/Rappster/filesystr

See Also

decomposePath, decomposePath-missing-method

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
64
65
66
67
68
69
## Not run: 

## Auxiliary function //
carefulCleanup <- function(x, pattern=basename(tempdir())) {
  out <- sapply(x, function(ii) {
    out <- NA
    if (grepl(pattern, ii)) {
      out <- unlink(ii, recursive=TRUE, force=TRUE)
    }        
    out
  })
  invisible(out)
}  
  
## Create example content //  
to_create <- file.path(tempdir(), "decomposePath", c("dir_a", file.path("dir_b", "sub_1")))
sapply(to_create, dir.create, recursive = TRUE, showWarnings = FALSE)
file.create(file.path(tempdir(), "decomposePath/dir_b/sub_1/file.txt"))

## Change working directory //
wd_0 <- getwd()
setwd(file.path(tempdir(), "decomposePath"))
## Make sure you undo this with 'setwd(wd_0)' when you are finished!!!

path <- c(
  ".",
  "..",
  "dir_a", 
  "dir_a/",
  "dir_b", 
  "dir_b/sub_1",
  "dir_b/sub_1/file.txt",
  "dir_b/sub_1/file.txt/",
  "dir_b/nonex",
  "dir_b/nonex/",
  "dir_b/nonex/file.txt",
  "nonex",
  "nonex/sub_1",
  "nonex/sub_1/file.txt",
  "nonex/foo.tgz", 
  "another nonex\\file.tar.gz", 
  "a_file", 
  "quux. quuux.tbz2", 
  "~/file.tar.xz",
  "", 
  NA_character_
)

res <- decomposePath(path = path)
res
class(res)

decomposePath(path = path, dir_slash = TRUE)
decomposePath(path = path, shortform = TRUE)
decomposePath(path = path, dir_slash = TRUE, shortform = TRUE)

decomposePath()
decomposePath(path = character())
decomposePath(path = NA_character_)

## Clean up //
## Reset working directory:
setwd(wd_0)

## Remove tempdir directory:
carefulCleanup(x = file.path(tempdir(), "decomposePath"))


## End(Not run)

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