Get the relative path of a path in a project relative to the current working directory
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.
from_root(..., root = proj_root(), error = TRUE)
... |
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. |
This function was inspired by here::here()
, and the major difference
is that it returns a relative path by default, which is more portable.
A relative path, or an error when the project root directory cannot
be determined or the conversion failed and error = TRUE
.
## Not run: xfun::from_root("data", "mtcars.csv") ## End(Not run)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.