Skip to content

Commit

Permalink
Proper fs::dir_tree() emulation
Browse files Browse the repository at this point in the history
 - for #43
  • Loading branch information
brownag committed Mar 20, 2023
1 parent 4bcceb6 commit a7fd239
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions R/taxonTree.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#' @param level One or more of: `"order"`, `"suborder"`, `"greatgroup"`, `"subgroup"`. The lowest level is passed to `getChildLevel()` to generate the leaf nodes.
#' @param root Label for root node. Default: `"Soil Taxonomy"`; `NULL` for "unrooted" tree.
#' @param verbose Print tree output? Default: `TRUE`
#' @param special.chars Characters used to print the tree to console. Default: `c("|", "|", "--")`. For fancy markup try: `c("\u251c", "\u2514", "\u2500 ")`
#' @param special.chars Characters used to print the tree to console. Default: `c("|--", "|", "|", "-")`. For fancy markup try: `c("\u251c", "\u2514", "\u2500 ")`
#' @param file Optional: path to output file. Default: `""` prints to standard output connection (unless redirected by `sink()`)
#' @param ... Additional arguments to `data.tree::as.Node.data.frame()`
#'
Expand All @@ -27,7 +27,7 @@ taxonTree <- function(taxon,
level = c("order", "suborder", "greatgroup", "subgroup"),
root = "Soil Taxonomy",
verbose = TRUE,
special.chars = c("|", "|", "--"),
special.chars = c("|--", "|", "|", "-"),
file = "",
...) {
if (!requireNamespace("data.tree")) {
Expand Down Expand Up @@ -72,14 +72,14 @@ print.SoilTaxonNode <- function(x,
res <- as.data.frame(x, ...)

# replace unicode markup
special.chars.default <- c("\u00a6", "\u00b0", "--")
special.chars.default <- c("\u00a6-", "\u00a6", "\u00b0", "-+")
if (is.null(special.chars) || length(special.chars) == 0) {
special.chars <- "|"
}

special.chars <- rep(special.chars, 3)[1:3]
for (i in 1:3) {
res$levelName <- gsub(special.chars.default[i], special.chars[i], res$levelName, fixed = TRUE)
special.chars <- rep(special.chars, 4)[1:4]
for (i in 1:4) {
res$levelName <- gsub(special.chars.default[i], special.chars[i], res$levelName)
}

cat(res$levelName, sep = "\n", file = file)
Expand Down
4 changes: 2 additions & 2 deletions man/taxonTree.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a7fd239

Please sign in to comment.