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