Given a directory, return the relative path that is relative to this
directory. For example, the path foo/bar.txt relative to the directory
foo/ is bar.txt, and the path /a/b/c.txt relative to
/d/e/ is ../../a/b/c.txt.
relative_path(x, dir = ".", use.. = TRUE, error = TRUE)A vector of paths to be converted to relative paths.
Path to a directory.
Whether to use double-dots (..) in the relative path. A
double-dot indicates the parent directory (starting from the directory
provided by the dir argument).
Whether to signal an error if a path cannot be converted to a relative path.
A vector of relative paths if the conversion succeeded; otherwise the
original paths when error = FALSE, and an error when error = TRUE.
xfun::relative_path("foo/bar.txt", "foo/")
#> [1] "bar.txt"
xfun::relative_path("foo/bar/a.txt", "foo/haha/")
#> [1] "../bar/a.txt"
xfun::relative_path(getwd())
#> [1] "."