View source: R/normalizePathCP.R
normalizePathCP | R Documentation |
normalizePath
Cross Platform: Returns absolute
path even for not (yet) existing files even on Linux.
On Windows, this is the default behaviour.
normalizePathCP(path, winslash = "/", mustWork = FALSE)
path |
Character vector of file paths |
winslash |
Path separator on Windows.
DEFAULT: "/" (unlike |
mustWork |
Logical for |
path character string(s)
Berry Boessenkool, berry-b@gmx.de, Nov 2017
normalizePath
, newFilename
normalizePath ("doesnotexist.file", mustWork=FALSE) # on unix not full path
normalizePathCP("doesnotexist.file") # full path on all platforms
normalizePath ("../doesnotexist.file", mustWork=FALSE)
normalizePathCP("../doesnotexist.file")
checknp <- function(a,b=a,d=getwd())
{
aa <- normalizePathCP(a)
bb <- if(d=="") b else paste0(d,"/",b)
if(aa != bb) stop("'", a, "' -> '", aa, "', should be '",bb, "'.")
aa
}
checknp("notexist.file")
checknp("../notexist.file", "notexist.file", dirname(getwd()))
checknp("notexistfolder/notexist.file")
#checknp("/home/berry/notexist.file", d="") # fails on windows
#checknp("S:/Dropbox/notexist.file",d="") # fails on linux
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.