Rev 54551 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
% File src/library/utils/man/normalizePath.Rd% Part of the R package, http://www.R-project.org% Copyright 1995-2010 R Core Development Team% Distributed under GPL 2 or later\name{normalizePath}\alias{normalizePath}\title{Express File Paths in Canonical Form}\description{Convert file paths to canonical form for the platform, to display themin a user-understandable form and so that relative and absolute paths canbe compared.}\usage{normalizePath(path, winslash = "\\\\", mustWork = NA)}\arguments{\item{path}{character vector of file paths.}\item{winslash}{the separator to be used on Windows -- ignoredelsewhere. Must be one of \code{c("/", "\\\\")}.}\item{mustWork}{logical: if \code{TRUE} then an error is given if the resultcannot be determined; if \code{NA} then a warning.}}\details{Tilde-expansion (see \code{\link{path.expand}}) is first done on\code{paths} (as from \R 2.13.0).Where the Unix-alike platform supports it attempts to turn paths intoabsolute paths in their canonical form (no \samp{./}, \samp{../} norsymbolic links). It relies on the POSIX system function\code{realpath}: if the platform does not have that (we know of nocurrent example) then the result will be an absolute path but mightnot be canonical. Even where \code{realpath} is used the canonicalpath need not be unique, for example \emph{via} hard links ormultiple mounts.On Windows it converts relative paths to absolute paths, convertsshort names for path elements to long names and ensures the separatoris that specified by \code{winslash}. It will match pathscase-insensitively and return the canonical case.UTF-8-encoded paths not valid in the current locale can be used.\code{mustWork = FALSE} is useful for expressing paths for use inmessages.}\value{A character vector.If an input is not a real path the result is system-dependent (unless\code{mustWork = TRUE}, when this should be an error). It will beeither the corresponding input element or a transformation of it intoan absolute path.Converting to an absolute file path can fail for a large number ofreasons. The most common are\itemize{\item One of more components of the file path does not exist.\item A component before the last is not a directory, or there isinsufficient permission to read the directory.\item For a relative path, the current directory cannot bedetermined.\item A symbolic link points to a non-existent place or links form aloop.\item The canonicalized path would be exceed the maximum supportedlength of a file path.}}#ifdef windows\seealso{\code{\link{shortPathName}}}#endif\examples{\donttest{ # random tempdircat(normalizePath(c(R.home(), tempdir())), sep = "\n")}}\keyword{ utilities }