EVOLUTION-MANAGER
Edit File: normalizePath.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Express File Paths in Canonical Form</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for normalizePath {base}"><tr><td>normalizePath {base}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Express File Paths in Canonical Form</h2> <h3>Description</h3> <p>Convert file paths to canonical form for the platform, to display them in a user-understandable form and so that relative and absolute paths can be compared. </p> <h3>Usage</h3> <pre> normalizePath(path, winslash = "\\", mustWork = NA) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>path</code></td> <td> <p>character vector of file paths.</p> </td></tr> <tr valign="top"><td><code>winslash</code></td> <td> <p>the separator to be used on Windows – ignored elsewhere. Must be one of <code>c("/", "\\")</code>.</p> </td></tr> <tr valign="top"><td><code>mustWork</code></td> <td> <p>logical: if <code>TRUE</code> then an error is given if the result cannot be determined; if <code>NA</code> then a warning.</p> </td></tr> </table> <h3>Details</h3> <p>Tilde-expansion (see <code><a href="path.expand.html">path.expand</a></code>) is first done on <code>paths</code>. </p> <p>Where the Unix-alike platform supports it attempts to turn paths into absolute paths in their canonical form (no <span class="samp">./</span>, <span class="samp">../</span> nor symbolic links). It relies on the POSIX system function <code>realpath</code>: if the platform does not have that (we know of no current example) then the result will be an absolute path but might not be canonical. Even where <code>realpath</code> is used the canonical path need not be unique, for example <em>via</em> hard links or multiple mounts. </p> <p>On Windows it converts relative paths to absolute paths, converts short names for path elements to long names and ensures the separator is that specified by <code>winslash</code>. It will match paths case-insensitively and return the canonical case. UTF-8-encoded paths not valid in the current locale can be used. </p> <p><code>mustWork = FALSE</code> is useful for expressing paths for use in messages. </p> <h3>Value</h3> <p>A character vector. </p> <p>If an input is not a real path the result is system-dependent (unless <code>mustWork = TRUE</code>, when this should be an error). It will be either the corresponding input element or a transformation of it into an absolute path. </p> <p>Converting to an absolute file path can fail for a large number of reasons. The most common are </p> <ul> <li><p> One of more components of the file path does not exist. </p> </li> <li><p> A component before the last is not a directory, or there is insufficient permission to read the directory. </p> </li> <li><p> For a relative path, the current directory cannot be determined. </p> </li> <li><p> A symbolic link points to a non-existent place or links form a loop. </p> </li> <li><p> The canonicalized path would be exceed the maximum supported length of a file path. </p> </li></ul> <h3>Note</h3> <p>The canonical form of paths may not be what you expect. For example, on macOS absolute paths such as ‘<span class="file">/tmp</span>’ and ‘<span class="file">/var</span>’ are symbolic links. On Linux, a path produced by bash process substitution is a symbolic link (such as ‘<span class="file">/proc/fd/63</span>’) to a pipe and there is no canonical form of such path. </p> <h3>Examples</h3> <pre># random tempdir cat(normalizePath(c(R.home(), tempdir())), sep = "\n") </pre> <hr /><div style="text-align: center;">[Package <em>base</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>