from_root: Get the relative path of a path in a project relative to the...

View source: R/paths.R

from_rootR Documentation

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 documentation built on Nov. 1, 2024, 1:06 a.m.