| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/path.R |
| 3 |
\name{path_expand} |
| 4 |
\alias{path_expand} |
| 5 |
\alias{path_expand_r} |
| 6 |
\alias{path_home} |
| 7 |
\alias{path_home_r} |
| 8 |
\title{Finding the User Home Directory} |
| 9 |
\usage{ |
| 10 |
path_expand(path) |
| 11 |
|
| 12 |
path_expand_r(path) |
| 13 |
|
| 14 |
path_home(...) |
| 15 |
|
| 16 |
path_home_r(...) |
| 17 |
} |
| 18 |
\arguments{ |
| 19 |
\item{path}{A character vector of one or more paths.} |
| 20 |
|
| 21 |
\item{...}{Additional paths appended to the home directory by \code{\link[=path]{path()}}.} |
| 22 |
} |
| 23 |
\description{ |
| 24 |
\itemize{ |
| 25 |
\item \code{path_expand()} performs tilde expansion on a path, replacing instances of |
| 26 |
\code{~} or \code{~user} with the user's home directory. |
| 27 |
\item \code{path_home()} constructs a path within the expanded users home directory, |
| 28 |
calling it with \emph{no} arguments can be useful to verify what fs considers the |
| 29 |
home directory. |
| 30 |
\item \code{path_expand_r()} and \code{path_home_r()} are equivalents which always use R's |
| 31 |
definition of the home directory. |
| 32 |
} |
| 33 |
} |
| 34 |
\details{ |
| 35 |
\code{path_expand()} differs from \code{\link[base:path.expand]{base::path.expand()}} in the interpretation of |
| 36 |
the home directory of Windows. In particular \code{path_expand()} uses the path |
| 37 |
set in the \code{USERPROFILE} environment variable and, if unset, then uses |
| 38 |
\code{HOMEDRIVE}/\code{HOMEPATH}. |
| 39 |
|
| 40 |
In contrast \code{\link[base:path.expand]{base::path.expand()}} first checks for \code{R_USER} then \code{HOME}, |
| 41 |
which in the default configuration of R on Windows are both set to the user's |
| 42 |
document directory, e.g. \verb{C:\\\\Users\\\\username\\\\Documents}. |
| 43 |
\code{\link[base:path.expand]{base::path.expand()}} also does not support \code{~otheruser} syntax on Windows, |
| 44 |
whereas \code{path_expand()} does support this syntax on all systems. |
| 45 |
|
| 46 |
This definition makes fs more consistent with the definition of home |
| 47 |
directory used on Windows in other languages, such as |
| 48 |
\href{https://docs.python.org/3/library/os.path.html#os.path.expanduser}{python} |
| 49 |
and \href{https://doc.rust-lang.org/std/env/fn.home_dir.html#windows}{rust}. This |
| 50 |
is also more compatible with external tools such as git and ssh, both of |
| 51 |
which put user-level files in \code{USERPROFILE} by default. It also allows you to |
| 52 |
write portable paths, such as \verb{~/Desktop} that points to the Desktop location |
| 53 |
on Windows, macOS and (most) Linux systems. |
| 54 |
|
| 55 |
Users can set the \code{R_FS_HOME} environment variable to override the |
| 56 |
definitions on any platform. |
| 57 |
} |
| 58 |
\examples{ |
| 59 |
# Expand a path |
| 60 |
path_expand("~/bin") |
| 61 |
|
| 62 |
# You can use `path_home()` without arguments to see what is being used as |
| 63 |
# the home diretory. |
| 64 |
path_home() |
| 65 |
path_home("R") |
| 66 |
|
| 67 |
# This will likely differ from the above on Windows |
| 68 |
path_home_r() |
| 69 |
} |
| 70 |
\seealso{ |
| 71 |
\href{https://cran.r-project.org/bin/windows/base/rw-FAQ.html#What-are-HOME-and-working-directories_003f}{R for Windows FAQ - 2.14} |
| 72 |
for behavior of \code{\link[base:path.expand]{base::path.expand()}}. |
| 73 |
} |