remove_common_root: Remove the Common Root Parts

Description Usage Arguments Examples

View source: R/remove_common_root.R

Description

Remove the Common Root Parts

Usage

1
remove_common_root(x, n_keep = 1L, dbg = TRUE)

Arguments

x

list of vectors of character as returned by strsplit or a vector of character.

n_keep

minimum number of segments to be kept in any case in the returned relative paths. For example, two paths "a" and "a/b" have the common root "a". Removing this root would result in relative paths "" and "b". As this is not useful, n_keep is 1 by default, making sure that all paths keep at least one segment (segment "a") in the example.

dbg

if TRUE debug messages are shown

Examples

1
2
3
4
5
6
7
8
9
# Split paths at the slashes
absparts <- strsplit(c("a/b/c", "a/b/d", "a/b/e/f/g", "a/b/hi"), "/")

# Remove the common parts of the paths
relparts <- remove_common_root(absparts)
relparts

# The extracted root is returned in attribute "root"
attr(relparts, "root")

KWB-R/kwb.file documentation built on Dec. 31, 2021, 8:15 p.m.