| path.contract | R Documentation |
Contract a path name, for example by replacing the user's home directory (if defined on that platform) with a leading tilde.
path.contract(path, ignore.case = os.windows, home = "~")
path |
character vector containing one or more path names. |
ignore.case |
|
home |
character string, the path to contract against. |
On Windows, paths are case insensitive, so something like
‘C:\Users\effective_user\Documents’ is regarded as
equivalent to ‘c:\users\effective_user\documents’.
Under Unix-alikes, paths are case sensitive, so something like
‘/home/effective_user’ is not equivalent to
‘/HOME/effective_user’.
By default, path.contract respects each of these behaviours, but can
be changed if desired.
Additionally, on Windows, the file separator may be either "/" or
"\\", for example
‘C:\Users\effective_user\Documents’ and
‘C:/Users/effective_user/Documents’ would be treated as
equivalent (or any mixture of the two, for example
‘C:/Users\effective_user/Documents’).
The 'path names' need not exist nor be valid path names.
A character vector of possibly contracted path names: where the home directory is unknown of none is specified the path is returned unchanged.
Using ./, ../, symbolic links, hard links, or multiple mounts
will NOT be resolved before attempting to contract path names. If you
wish to resolve these before contracting path names, see
normalizePath.
path.expand, basename,
normalizePath, file.path.
stopifnot(path.contract(path.expand(x <- c("~", "~/foo"))) == x)
# Note that this is not necessarily true the other way around (in Windows)
# simply because the path separator may have changed
tilde <- path.expand("~")
if (tilde == "~") {
cat("the home directory is unknown or none is specified\n")
} else {
paths <- file.path(c(tilde, toupper(tilde), tolower(tilde)), "foo")
print(cbind(
Path = paths,
`Contracted Path` = path.contract(paths),
`Contracted Path (ignoring case)` = path.contract(paths, ignore.case = TRUE),
`Contracted Path (with case)` = path.contract(paths, ignore.case = FALSE)
), quote = FALSE)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.