DBScan
1
How can I create figures which display the file structure like a tree, for instance like this (taken from 12.2 Project structure | R Markdown: The Definitive Guide (bookdown.org)?
I am using Quarto.
directory/
├── index.Rmd
├── 01-intro.Rmd
├── 02-literature.Rmd
├── 03-method.Rmd
├── 04-application.Rmd
├── 05-summary.Rmd
├── 06-references.Rmd
├── _bookdown.yml
├── _output.yml
├── book.bib
├── preamble.tex
├── README.md
└── style.css
Hi @DBScan. I've found the data.tree
package very useful in creating file structure displays.
library(data.tree)
# example data
df = data.frame(var1 = 'directory',
var2 = c('index.Rmd',
'intro.Rmd',
'literature.Rmd',
'method.Rmd',
'application.Rmd',
'summary.Rmd',
'references.Rmd',
'bookdown.yml',
'output.yml',
'book.bib',
'preamble.tex',
'README.md',
'style.css')
)
# create pathString to establish the file hierarchy
df$pathString = paste(df$var1, df$var2, sep = '/')
as.Node(df)
#> levelName
#> 1 directory
#> 2 ¦--index.Rmd
#> 3 ¦--intro.Rmd
#> 4 ¦--literature.Rmd
#> 5 ¦--method.Rmd
#> 6 ¦--application.Rmd
#> 7 ¦--summary.Rmd
#> 8 ¦--references.Rmd
#> 9 ¦--bookdown.yml
#> 10 ¦--output.yml
#> 11 ¦--book.bib
#> 12 ¦--preamble.tex
#> 13 ¦--README.md
#> 14 °--style.css
Created on 2024-01-16 with reprex v2.0.2
DBScan
3
Thanks @scottyd22, this looks quite useful.
In the end, I ended up with querying my file structure with the tree
command in the terminal and then copy-paste in the Quarto document.
1 Like
As a quarto chunk:
```{r}
library(fs)
cat(dir_tree(path = "~/directory", recurse = TRUE))
```
2 Likes
system
Closed
5
This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.
If you have a query related to it or one of the replies, start a new topic and refer back with a link.