Remove the Common Root Parts

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

# 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)
#> Removing the first 2 path segments ... ok. (0.00s)
relparts
#> [[1]] #> [1] "c" #> #> [[2]] #> [1] "d" #> #> [[3]] #> [1] "e" "f" "g" #> #> [[4]] #> [1] "hi" #> #> attr(,"root") #> [1] "a/b"
# The extracted root is returned in attribute "root" attr(relparts, "root")
#> [1] "a/b"