normalizePathCP {berryFunctions} | R Documentation |
normalizePath Cross Platform
Description
normalizePath
Cross Platform: Returns absolute
path even for not (yet) existing files even on Linux.
On Windows, this is the default behaviour.
Usage
normalizePathCP(path, winslash = "/", mustWork = FALSE)
Arguments
path |
Character vector of file paths |
winslash |
Path separator on Windows.
DEFAULT: "/" (unlike |
mustWork |
Logical for |
Value
path character string(s)
Author(s)
Berry Boessenkool, berry-b@gmx.de, Nov 2017
See Also
Examples
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
[Package berryFunctions version 1.22.5 Index]