normPath | R Documentation |
Checks the specified path for formatting consistencies:
use slash instead of backslash;
do tilde etc. expansion;
remove trailing slash.
normPath(path)
## S4 method for signature 'character'
normPath(path)
## S4 method for signature 'list'
normPath(path)
## S4 method for signature 'NULL'
normPath(path)
## S4 method for signature 'missing'
normPath()
## S4 method for signature 'logical'
normPath(path)
normPathRel(path)
path |
A character vector of filepaths. |
Additionally, normPath()
attempts to create a absolute paths,
whereas normPathRel()
maintains relative paths.
d> getwd() [1] "/home/achubaty/Documents/GitHub/PredictiveEcology/reproducible" d> normPathRel("potato/chips") [1] "potato/chips" d> normPath("potato/chips") [1] "/home/achubaty/Documents/GitHub/PredictiveEcology/reproducible/potato/chips"
Character vector of cleaned up filepaths.
## normalize file paths
paths <- list("./aaa/zzz",
"./aaa/zzz/",
".//aaa//zzz",
".//aaa//zzz/",
".\\\\aaa\\\\zzz",
".\\\\aaa\\\\zzz\\\\",
file.path(".", "aaa", "zzz"))
checked <- normPath(paths)
length(unique(checked)) ## 1; all of the above are equivalent
## check to see if a path exists
tmpdir <- file.path(tempdir(), "example_checkPath")
dir.exists(tmpdir) ## FALSE
tryCatch(checkPath(tmpdir, create = FALSE), error = function(e) FALSE) ## FALSE
checkPath(tmpdir, create = TRUE)
dir.exists(tmpdir) ## TRUE
unlink(tmpdir, recursive = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.