Expand ~ in File Paths

DESCRIPTION:

Expand a file path by replacing a leading tilde, "~", with the user's home directory. On UNIX systems, a leading "~user" will be replaced by that user's home directory in the file path.

USAGE:

path.expand(path)

REQUIRED ARGUMENTS:

path
a character vector giving one or more path names.

VALUE:

a character vector containing one string for each string in path . These file paths have been expanded if "~" (or "~user" on UNIX) is at the beginning of a file path string.

DETAILS:

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.

SEE ALSO:

, , , .

EXAMPLES:

# 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")))