Learn R Programming

this.path (version 0.5.1)

as.relative.path: Make a Path Relative to Another Path

Description

When working with this.path, you will be dealing with a lot of absolute paths. These paths are no good for saving within files, so you'll need to use as.relative.path() to turn your absolute paths into relative paths.

Usage

as.relative.path(path, relative.to = this.dir(verbose = FALSE))
as.rel.path     (path, relative.to = this.dir(verbose = FALSE))

Arguments

path

character vector of file / / URL paths.

relative.to

character string; the file / / URL path to make path relative to.

Value

character vector of the same length as path.

Details

Tilde-expansion (see path.expand) is first done on path and relative.to.

If path and relative.to are equivalent, "." will be returned. If path and relative.to have no base in common, the normalized path will be returned.

Examples

Run this code
# NOT RUN {
# Windows example


# as.relative.path(
#     c(
#         # paths which are equivalent will return .
#         "C:/Users/effective_user/Documents/this.path/man",
#
#
#         # paths which have no base in common return as themselves
#         "https://raw.githubusercontent.com/ArcadeAntics/this.path/main/tests/this.path_w_URLs.R",
#         "D:/",
#         "//host-name/share-name/path/to/file",
#
#
#         "C:/Users/effective_user/Documents/testing",
#         "C:\\Users\\effective_user",
#         "C:/Users/effective_user/Documents/R/this.path.R"
#     ),
#     "C:/Users/effective_user/Documents/this.path/man"
# )


# Unix-alikes example


# as.relative.path(
#     c(
#         # paths which are equivalent will return .
#         "/users/effective_user/Documents/this.path/man",
#
#
#         # paths which have no base in common return as themselves
#         "https://raw.githubusercontent.com/ArcadeAntics/this.path/main/tests/this.path_w_URLs.R",
#         "//host-name/share-name/path/to/file",
#
#
#         "/users/effective_user/Documents/testing",
#         "/users/effective_user",
#         "/users/effective_user/Documents/R/this.path.R"
#     ),
#     "/users/effective_user/Documents/this.path/man"
# )
# }

Run the code above in your browser using DataLab