path.expand {base}R Documentation

Expand File Paths


Expand a path name, for example by replacing a leading tilde by the user's home directory (if defined on that platform).





character vector containing one or more path names.


On Unix - alikes:

On most builds of R a leading ~user will expand to the home directory of user (since R 4.1.0 also without readline in use).

There are possibly different concepts of ‘home directory’: that usually used is the setting of the environment variable HOME.

The ‘path names’ need not exist nor be valid path names but they do need to be representable in the session encoding.

On Windows:

The definition of the ‘home’ directory is in the ‘rw-FAQ’ Q2.14: it is taken from the R_USER environment variable when path.expand is first called in a session.

The ‘path names’ need not exist nor be valid path names.


A character vector of possibly expanded path names: where the home directory is unknown or none is specified the path is returned unchanged.

If the expansion would exceed the maximum path length the result may be truncated or the path may be returned unchanged.

See Also

basename, normalizePath, file.path.



[Package base version 4.3.0 Index]