The hardware and bandwidth for this mirror is donated by dogado GmbH, the Webhosting and Full Service-Cloud Provider. Check out our Wordpress Tutorial.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]dogado.de.
Print the tree for current working directory
tmp <- tempdir()
demo <- file.path(tmp, "printtree-demo")
# Start fresh
if (dir.exists(demo)) unlink(demo, recursive = TRUE, force = TRUE)
dir.create(demo, recursive = TRUE)
dir.create(file.path(demo, "R"))
dir.create(file.path(demo, "data", "raw"), recursive = TRUE)
file.create(file.path(demo, "R", "hello.R"))
#> [1] TRUE
file.create(file.path(demo, "README.md"))
#> [1] TRUE
file.create(file.path(demo, ".Rhistory"))
#> [1] TRUEPrint the tree
When project = “root”, printtree can walk upward from the provided path to detect a project root using simple markers. By default this includes:
.Rproj files (RStudio / Posit projects)
DESCRIPTION files (R package roots)
In this example, we mark demo as a package-like root by creating a DESCRIPTION file, then print from a subdirectory:
file.create(file.path(demo, "DESCRIPTION"))
#> [1] TRUE
subdir <- file.path(demo, "data", "raw")
print_rtree(subdir, project = "root")
#> printtree-demo/
#> |-- data/
#> | `-- raw/
#> |-- R/
#> | `-- hello.R
#> |-- DESCRIPTION
#> `-- README.md
#>
#> 3 directories, 3 filesYou can customize detection using rootmarkers:
Limit depth:
print_rtree(max_depth = 2)
#> vignettes/
#> |-- feature-tour.html
#> |-- feature-tour.R
#> |-- feature-tour.Rmd
#> |-- printtree.R
#> |-- printtree.Rmd
#> |-- tree-dark.png
#> |-- tree-white.png
#> `-- tree.png
#>
#> 0 directories, 8 filesBy default, output ends with a count summary for the displayed tree:
print_rtree(demo, max_depth = 1)
#> printtree-demo/
#> |-- data/
#> |-- R/
#> |-- DESCRIPTION
#> `-- README.md
#>
#> 2 directories, 2 filesSuppress the footer when you want the older compact output:
print_rtree(demo, max_depth = 1, count_footer = FALSE)
#> printtree-demo/
#> |-- data/
#> |-- R/
#> |-- DESCRIPTION
#> `-- README.mdIgnore exact names or patterns. With the default
ignore_type = "auto", wildcard values are treated as glob
patterns:
file.create(file.path(demo, "debug.log"))
#> [1] TRUE
print_rtree(demo, ignore = c("*.log", ".Rhistory"), max_depth = 2)
#> printtree-demo/
#> |-- data/
#> | `-- raw/
#> |-- R/
#> | `-- hello.R
#> |-- DESCRIPTION
#> `-- README.md
#>
#> 3 directories, 3 filesUse regular expressions when you need them:
print_rtree(demo, ignore = "^README", ignore_type = "regex", max_depth = 1)
#> printtree-demo/
#> |-- data/
#> |-- R/
#> |-- debug.log
#> `-- DESCRIPTION
#>
#> 2 directories, 2 filesPrune directories that have no displayable children:
dir.create(file.path(demo, "logs"))
file.create(file.path(demo, "logs", "debug.log"))
#> [1] TRUE
print_rtree(demo, ignore = "*.log", prune = TRUE)
#> printtree-demo/
#> |-- R/
#> | `-- hello.R
#> |-- DESCRIPTION
#> `-- README.md
#>
#> 1 directory, 3 filesShow hidden files:
print_rtree(demo, show_hidden = TRUE, max_depth = 2)
#> printtree-demo/
#> |-- data/
#> | `-- raw/
#> |-- logs/
#> | `-- debug.log
#> |-- R/
#> | `-- hello.R
#> |-- debug.log
#> |-- DESCRIPTION
#> `-- README.md
#>
#> 4 directories, 5 filesUse unicode tree glyphs (if your terminal supports them):
print_rtree(demo, format = "unicode", max_depth = 2)
#> printtree-demo/
#> ├── data/
#> │ └── raw/
#> ├── logs/
#> │ └── debug.log
#> ├── R/
#> │ └── hello.R
#> ├── debug.log
#> ├── DESCRIPTION
#> └── README.md
#>
#> 4 directories, 5 filesAnnotate files with Git status when the tree is inside a Git work tree:
Use quiet = TRUE when you want to capture lines without
printing:
lines <- print_rtree(demo, return_lines = TRUE, quiet = TRUE)
head(lines)
#> [1] "printtree-demo/" "|-- data/" "| `-- raw/"
#> [4] "|-- logs/" "| `-- debug.log" "|-- R/"Write a tree to a text or Markdown file:
tree_md <- file.path(tempdir(), "printtree-output", "tree.md")
write_tree(demo, tree_md, format = "md", title = "Demo Tree")Generate a PNG snapshot:
# Save PNG snapshots
png_light <- tempfile("tree-light-", fileext = ".png")
png_dark <- tempfile("tree-dark-", fileext = ".png")
# Light (white bg, black text)
print_rtree(demo, snapshot = TRUE, snapshot_bg = "white", snapshot_file = png_light)
#> printtree-demo/
#> |-- data/
#> | `-- raw/
#> |-- logs/
#> | `-- debug.log
#> |-- R/
#> | `-- hello.R
#> |-- debug.log
#> |-- DESCRIPTION
#> `-- README.md
#>
#> 4 directories, 5 files
# Dark (black bg, white text)
print_rtree(demo, snapshot = TRUE, snapshot_bg = "black", snapshot_file = png_dark)
#> printtree-demo/
#> |-- data/
#> | `-- raw/
#> |-- logs/
#> | `-- debug.log
#> |-- R/
#> | `-- hello.R
#> |-- debug.log
#> |-- DESCRIPTION
#> `-- README.md
#>
#> 4 directories, 5 filesThese binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.
Health stats visible at Monitor.