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.

Feature tour

library(printtree)

This article walks through the output features added in printtree 0.2.1.

demo <- file.path(tempdir(), "printtree-feature-tour")
if (dir.exists(demo)) unlink(demo, recursive = TRUE, force = TRUE)

dir.create(file.path(demo, "R"), recursive = TRUE)
dir.create(file.path(demo, "data", "raw"), recursive = TRUE)
dir.create(file.path(demo, "logs"), recursive = TRUE)
dir.create(file.path(demo, "empty"), recursive = TRUE)

file.create(file.path(demo, "R", "helpers.R"))
#> [1] TRUE
file.create(file.path(demo, "README.md"))
#> [1] TRUE
file.create(file.path(demo, "data", "raw", "sales.csv"))
#> [1] TRUE
file.create(file.path(demo, "logs", "debug.log"))
#> [1] TRUE
file.create(file.path(demo, "test_cache"))
#> [1] TRUE

Count summaries

By default, print_rtree() ends with a displayed directory/file count.

print_rtree(demo, max_depth = 2)
#> printtree-feature-tour/
#> |-- data/
#> |   `-- raw/
#> |-- empty/
#> |-- logs/
#> |   `-- debug.log
#> |-- R/
#> |   `-- helpers.R
#> |-- README.md
#> `-- test_cache
#> 
#> 5 directories, 4 files

Set count_footer = FALSE for compact output.

print_rtree(demo, max_depth = 1, count_footer = FALSE)
#> printtree-feature-tour/
#> |-- data/
#> |-- empty/
#> |-- logs/
#> |-- R/
#> |-- README.md
#> `-- test_cache

Pattern ignores

The ignore argument still supports exact basenames, but with ignore_type = "auto" it also treats wildcard entries as glob patterns.

print_rtree(demo, ignore = c("*.log", "test_*"), max_depth = 2)
#> printtree-feature-tour/
#> |-- data/
#> |   `-- raw/
#> |-- empty/
#> |-- logs/
#> |-- R/
#> |   `-- helpers.R
#> `-- README.md
#> 
#> 5 directories, 2 files

You can opt into regular expression matching for more control.

print_rtree(demo, ignore = "^(README|test_)", ignore_type = "regex", max_depth = 1)
#> printtree-feature-tour/
#> |-- data/
#> |-- empty/
#> |-- logs/
#> `-- R/
#> 
#> 4 directories, 0 files

Prune empty directories

Use prune = TRUE to hide directories with no displayable children after ignores and depth limits are applied.

print_rtree(demo, ignore = "*.log", prune = TRUE)
#> printtree-feature-tour/
#> |-- data/
#> |   `-- raw/
#> |       `-- sales.csv
#> |-- R/
#> |   `-- helpers.R
#> |-- README.md
#> `-- test_cache
#> 
#> 3 directories, 4 files

Quiet capture

Use quiet = TRUE with return_lines = TRUE when you want to work with the tree programmatically.

lines <- print_rtree(demo, return_lines = TRUE, quiet = TRUE)
head(lines, 4)
#> [1] "printtree-feature-tour/" "|-- data/"              
#> [3] "|   `-- raw/"            "|       `-- sales.csv"

Text and Markdown export

write_tree() writes the same tree output to a text or Markdown file. Parent directories are created automatically by default.

tree_md <- file.path(tempdir(), "printtree-feature-tour-output", "tree.md")
write_tree(demo, tree_md, format = "md", title = "Feature Tour Tree")
readLines(tree_md, n = 8)
#> [1] "# Feature Tour Tree"     ""                       
#> [3] "```"                     "printtree-feature-tour/"
#> [5] "|-- data/"               "|   `-- raw/"           
#> [7] "|       `-- sales.csv"   "|-- empty/"

Git status annotations

When the target folder is inside a Git work tree, git = TRUE annotates changed paths with simple status markers and includes a legend.

The example is not evaluated when building the vignette so automated checks do not depend on an external Git executable or repository configuration.

# From inside an existing Git repository:
print_rtree(".", git = TRUE)

# Hide the legend when you already know the markers:
print_rtree(".", git = TRUE, git_legend = FALSE)

These 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.