Learn R Programming

berryFunctions (version 1.22.5)

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

Value

path character string(s)

Arguments

path

Character vector of file paths

winslash

Path separator on Windows. DEFAULT: "/" (unlike normalizePath)

mustWork

Logical for normalizePath. DEFAULT: FALSE

Author

Berry Boessenkool, berry-b@gmx.de, Nov 2017

See Also

normalizePath, newFilename

Examples

Run this code

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

Run the code above in your browser using DataLab