Debian Codegraph @

man/relative_path.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/paths.R
3 \name{relative_path}
4 \alias{relative_path}
5 \title{Get the relative path of a path relative to a directory}
6 \usage{
7 relative_path(x, dir = ".", use.. = TRUE, error = TRUE)
8 }
9 \arguments{
10 \item{x}{A vector of paths to be converted to relative paths.}
11
12 \item{dir}{Path to a directory.}
13
14 \item{use..}{Whether to use double-dots (\file{..}) in the relative path. A
15 double-dot indicates the parent directory (starting from the directory
16 provided by the \code{dir} argument).}
17
18 \item{error}{Whether to signal an error if a path cannot be converted to a
19 relative path.}
20 }
21 \value{
22 A vector of relative paths if the conversion succeeded; otherwise the
23 original paths when \code{error = FALSE}, and an error when \code{error = TRUE}.
24 }
25 \description{
26 Given a directory, return the relative path that is relative to this
27 directory. For example, the path \file{foo/bar.txt} relative to the directory
28 \file{foo/} is \file{bar.txt}, and the path \file{/a/b/c.txt} relative to
29 \file{/d/e/} is \file{../../a/b/c.txt}.
30 }
31 \examples{
32 xfun::relative_path("foo/bar.txt", "foo/")
33 xfun::relative_path("foo/bar/a.txt", "foo/haha/")
34 xfun::relative_path(getwd())
35 }