path.expand(path)
path
. These file paths have
been expanded if "~" (or "~user" on UNIX) is at the beginning
of a file path string.
On Windows, HOMEDRIVE and HOMEPATH are combined to determine the value of "~", and on UNIX systems "~" is replaced with the value of the environment variable HOME.
On UNIX systems, the string "~user" at the beginning of a
path
string will be replaced with the
home directory of "user" if there is a user of that name.
Because
path.expand
calls
file.path
, the returned
path names will have directory separator characters that
are appropriate for the current platform.
This function emulates the R function
path.expand
.
# The ~ is expanded and the directory separator is replaced with correct one path.expand("~/foo1\\foo2") # List all directories in user's home directory list.files(path.expand("~"), type="directories") # Look for user's S-PLUS data directories file.exists(path.expand(c("~/MySwork/.Data","~/.Data")))