## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

## ----setup--------------------------------------------------------------------
library(printtree)

## ----demo-tree----------------------------------------------------------------
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"))
file.create(file.path(demo, "README.md"))
file.create(file.path(demo, "data", "raw", "sales.csv"))
file.create(file.path(demo, "logs", "debug.log"))
file.create(file.path(demo, "test_cache"))

## ----count-summary------------------------------------------------------------
print_rtree(demo, max_depth = 2)

## ----compact-output-----------------------------------------------------------
print_rtree(demo, max_depth = 1, count_footer = FALSE)

## ----glob-ignore--------------------------------------------------------------
print_rtree(demo, ignore = c("*.log", "test_*"), max_depth = 2)

## ----regex-ignore-------------------------------------------------------------
print_rtree(demo, ignore = "^(README|test_)", ignore_type = "regex", max_depth = 1)

## ----prune--------------------------------------------------------------------
print_rtree(demo, ignore = "*.log", prune = TRUE)

## ----quiet-capture------------------------------------------------------------
lines <- print_rtree(demo, return_lines = TRUE, quiet = TRUE)
head(lines, 4)

## ----write-tree---------------------------------------------------------------
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)

## ----git-status, eval = FALSE-------------------------------------------------
# # 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)

