Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

from_root

Get the relative path of a path in a project relative to the current working directory


Description

First compose an absolute path using the project root directory and the relative path components, i.e., file.path(root, ...). Then convert it to a relative path with relative_path(), which is relative to the current working directory.

Usage

from_root(..., root = proj_root(), error = TRUE)

Arguments

...

A character vector of path components relative to the root directory of the project.

root

The root directory of the project.

error

Whether to signal an error if the path cannot be converted to a relative path.

Details

This function was inspired by here::here(), and the major difference is that it returns a relative path by default, which is more portable.

Value

A relative path, or an error when the project root directory cannot be determined or the conversion failed and error = TRUE.

Examples

## Not run: 
xfun::from_root("data", "mtcars.csv")

## End(Not run)

xfun

Miscellaneous Functions to Support Packages Maintained by 'Yihui Xie'

v0.22
MIT + file LICENSE
Authors
Yihui Xie [aut, cre, cph] (<https://orcid.org/0000-0003-0645-5666>), Wush Wu [ctb], Daijiang Li [ctb], Xianying Tan [ctb], Salim Brüggemann [ctb] (<https://orcid.org/0000-0002-5329-5987>), Christophe Dervieux [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.