path.expand
Expand ~ in File Paths

Description

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

Usage

path.expand(path)

Arguments

path a character vector giving one or more path names.

Details

On Windows, the leading tilde "~" is replaced with the environment variable R_USER. 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 is replaced with the home directory of "user" if there is a user of that name.
Value
returns a character vector containing one string for each string in path. These file paths are expanded if "~" (or "~user" on UNIX) is at the beginning of a file path string.
Differences between TIBCO Enterprise Runtime for R and Open-source R
In open-source R, path.expand() appears to save the value used for "~" the first time it is called. Even if the environment variables R_USER, and so on, are changed, further calls to path.expand do not use these environment variables to determine the value for "~". In contrast, TIBCO Enterprise Runtime for R reads the current values for R_USER, and so on, whenever path.expand is called.
See Also
file.path, file.exists, list.files, Sys.getenv, normalizePath.
Examples
# The ~ is expanded to the user's home directory
path.expand("~/foo")

# on unix, ~bill is expanded to the home directory of user 'bill' path.expand("~bill/foo")

# List all files in user's home directory list.files(path.expand("~"))

Package base version 6.0.0-69
Package Index