sen2r (version 1.2.1)

abs2rel: Convert a path to a relative path

Description

The function convert an absolute path to a relative path in respect to a reference. The longest common parent directory is taken as reference. Symbolic links are converted to original paths before performing the operation.

Usage

abs2rel(path, ref_path, mustWork = NA)

Arguments

path

The path to be converted (if it is not absolute, the current working directory is considered as its parent, and a warning is shown).

ref_path

The reference path to be compared to path to obtain the relative directory. Important: the path is considered as a directory also if it is the path of a file!

mustWork

(optional) logical: if TRUE an error is given if path or ref_path do not exists; if NA (default) then a warning; if FALSE nothing is shown.

Value

The relative path

Examples

Run this code
# NOT RUN {
# the reference path
(ref_path <- system.file(package="sen2r"))
# a path with a common parent with ref_path
(in_path_1 <- system.file(package="gdalUtils"))
# a path included in ref_path
(in_path_2 <- system.file("R/abs2rel.R", package="sen2r"))
# a path external to ref_path (in Linux)
(in_path_3 <- system.file(package="base"))
# an unexisting path
(in_path_4 <- gsub("sen2r","r2sen",ref_path))

abs2rel(in_path_1, ref_path)

abs2rel(in_path_2, ref_path)

suppressWarnings(abs2rel(in_path_3, ref_path))

suppressWarnings(abs2rel(in_path_4, ref_path, mustWork=FALSE))

suppressWarnings(abs2rel(ref_path, ref_path))
# }

Run the code above in your browser using DataLab