iso_shorten_relative_paths: Shorten relative paths

Description Usage Arguments Value See Also Examples

View source: R/utils.R

Description

Convenience function to shorten relative paths based on overlap with the provided root(s). Also simplifies current directory repeats (e.g. "././." becomes ".") for better legibility. Does not check whether the original or resulting paths point to valid files or folders. Relative paths that do not start with the supplied root default back to the current working directory (.). Absolute paths are allowed but are returned as is without attempts at shortening. See iso_find_absolute_path_roots for rooting absolute paths.

Usage

1
iso_shorten_relative_paths(path, root = ".")

Arguments

path

vector of file/folder paths, mixed relative and absolute paths are allowed.

root

root directory for the isofiles. Can be relative to the current working directory (e.g. "data") or an absolute path on the file system (e.g. "/Users/..." or "C:/Data/.."). The default is the current working directory ("."). Can be supplied as a vector of same length as the provided paths if the paths have different roots.

Value

a data frame with the root directories and paths relative to the root - order of input paths is preserved

See Also

Other file system functions: iso_expand_paths(), iso_find_absolute_path_roots(), iso_root_paths()

Examples

1
2
3
4
iso_shorten_relative_paths(file.path("A", "B", "C"), "A") # root = "A", path = B/C
iso_shorten_relative_paths(file.path("A", "B", "C"), file.path("A", "B")) # root = "A/B", path = "C"
iso_shorten_relative_paths(file.path("A", "C", "D"), file.path("A", "B")) # root = "A", path = "C/D"
iso_shorten_relative_paths(file.path("A", "B", "C"), "B") # root = ".", path stays "A/B/C"

isoreader documentation built on Nov. 19, 2021, 1:07 a.m.