normalizePath
Express File Paths in Canonical Form

Description

Convert file paths to canonical form on the Unix or Windows platforms.

Usage

normalizePath(path, winslash="\\", mustWork = NA)

Arguments

path a character vector giving one or more path names.
winslash a character string giving the path separator to use when forming canonical paths. On Windows, this argument must be the single string "/" or "\\". On Unix, this argument is ignored.
mustWork a logical value specifying whether the files in path must exist.
  • If NA (the default), a warning is generated for each file that does not exist.
  • If TRUE, an error is generated if any of the specified files does not exist.
  • If FALSE, no errors or warnings are generated.

Details

The file paths are passed to path.expand to expand any leading tilde "~" character.
Any file paths that are relative paths are interpreted relative to the current working directory.
If a file path specifies an existing file or directory, the path is converted to an absolute path in the canonical form without "./" or "../" components. If a file path does not specify an existing file or directory, it is not changed.
Value
returns a character vector containing the canonical form of the file paths.
See Also
getwd, file.path, path.expand
Examples
# on Windows, gives the user the directory using "/" path separator
normalizePath("~","/")

# gives absolute file name of "aa", if this file exists # otherwise just returns "aa" normalizePath("aa", mustWork=FALSE)

# gives absolute file name of "aa", if this file exists # otherwise gives a warning and returns "aa" normalizePath("aa", mustWork=NA)

Package base version 6.1.4-13
Package Index