file.path()
   get_help() docs


Description

The file.path() function comes with R and is part of the Base R {base} package.

We use this function to write paths to files or directories (even though it’s called file.path()!), in a way where the path is guaranteed to work on any type of computer or operating system.

Conceptual Usage

file.path('component', 'of', 'path', 'to', 'thing', 'of', 'interest')

Examples

# Format path to a file that lives in the relative path 'path/to/data/file.txt'
file.path('path', 'to', 'data', 'file.txt')
## [1] "path/to/data/file.txt"


# Format path to a file that lives in the relative path '../path/to/data/file.txt'
file.path('..', 'path', 'to', 'data', 'file.txt')
## [1] "../path/to/data/file.txt"


# Format path to directory at the relative path '../../path/to/data/'
file.path('..', '..', 'path', 'to', 'data')
## [1] "../../path/to/data"