Here's a possible approach to get what you originally asked for - a system like a tree. This will give the data.tree object which is flexible enough and can be created to plot the chart as you possibly want, but I donβt quite understand what you want:
path <- c( "root/a/some/file.R", "root/a/another/file.R", "root/a/another/cool/file.R", "root/b/some/data.csv", "root/b/more/data.csv" ) library(data.tree); library(plyr) x <- lapply(strsplit(path, "/"), function(z) as.data.frame(t(z))) x <- rbind.fill(x) x$pathString <- apply(x, 1, function(x) paste(trimws(na.omit(x)), collapse="/")) (mytree <- data.tree::as.Node(x)) 1 root 2 Β¦--a 3 Β¦ Β¦--some 4 Β¦ Β¦ Β°--file.R 5 Β¦ Β°--another 6 Β¦ Β¦--file.R 7 Β¦ Β°--cool 8 Β¦ Β°--file.R 9 Β°--b 10 Β¦--some 11 Β¦ Β°--data.csv 12 Β°--more 13 Β°--data.csv plot(mytree)
You can get the parts you need (I think), but this will require you to do some of the work and data.tree conversion between data types in data.tree : https://cran.r-project.org/web/packages/ data.tree / vignettes /data.tree.html # conversion tree
I use this approach in my pathr package tree function when use.data.tree = TRUE https://github.com/trinker/pathr#tree
EDIT For @Luke's comment below ... data.tree::as.Node takes a path:
(mytree <- data.tree::as.Node(data.frame(pathString = path))) levelName 1 root2 2 Β¦--a 3 Β¦ Β¦--some 4 Β¦ Β¦ Β°--file.R 5 Β¦ Β°--another 6 Β¦ Β¦--file.R 7 Β¦ Β°--cool 8 Β¦ Β°--file.R 9 Β°--b 10 Β¦--some 11 Β¦ Β°--data.csv 12 Β°--more 13 Β°--data.csv
source share