Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
gluc committed Nov 12, 2023
2 parents 4a6ec7a + 0f58f6c commit 808dd38
Show file tree
Hide file tree
Showing 28 changed files with 336 additions and 96 deletions.
4 changes: 3 additions & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
^\.travis\.yml$
data_gen
cran-comments.md
cheat-sheet.md
publish-cheat-sheet.md
getting-started-with-development.md
appveyor.yml
travis-tool.sh.cmd
Rprof.out
^appveyor\.yml$
revdep
README.md
^CRAN-RELEASE$
^\.github$
1 change: 1 addition & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.html
49 changes: 49 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: R-CMD-check

jobs:
R-CMD-check:
runs-on: ${{ matrix.config.os }}

name: ${{ matrix.config.os }} (${{ matrix.config.r }})

strategy:
fail-fast: false
matrix:
config:
- {os: macos-latest, r: 'release'}
- {os: windows-latest, r: 'release'}
- {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'}
- {os: ubuntu-latest, r: 'release'}
- {os: ubuntu-latest, r: 'oldrel-1'}

env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes

steps:
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
with:
r-version: ${{ matrix.config.r }}
http-user-agent: ${{ matrix.config.http-user-agent }}
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
needs: check

- uses: r-lib/actions/check-r-package@v2
with:
upload-snapshots: true
2 changes: 0 additions & 2 deletions CRAN-RELEASE

This file was deleted.

12 changes: 6 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: data.tree
Type: Package
Title: General Purpose Hierarchical Data Structure
Version: 1.0.0
Date: 2020-07-31
Version: 1.1.0
Date: 2023-11-11
Authors@R: c(
person(
"Russ", "Hyde",
Expand Down Expand Up @@ -48,7 +48,7 @@ Authors@R: c(
"Christoph", "Glur"
, role = c("aut", "cre")
, comment = "R interface"
, email = "christoph.glur@ipub.com"
, email = "christoph.glur@powerpartners.pro"
)
)
VignetteBuilder:
Expand Down Expand Up @@ -84,9 +84,9 @@ Description: Create tree structures from hierarchical data, and traverse the
data.frame and more. Useful for decision trees, machine learning, finance,
conversion from and to JSON, and many other applications.
License: GPL (>= 2)
URL: http://github.com/gluc/data.tree
BugReports: http://github.com/gluc/data.tree/issues
URL: https://github.com/gluc/data.tree
BugReports: https://github.com/gluc/data.tree/issues
Depends:
R (>= 3.5)
RoxygenNote: 7.1.1
RoxygenNote: 7.2.3
Encoding: UTF-8
7 changes: 7 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# All changes to data.tree are documented here.

## Version 1.1.0
- IMPROVE: Node names may no longer be `NA`. It was not fully supported, and now it is an error. (#152)
- FIX: changed lock_object to lock_objects (#149 thx to Olly Beagly)
- FIX: help('data.tree') works again
- IMPROVE: FromListSimple and as.Node.list now have an additional parameter 'interpretNullAsList'. See #169 for details.
- IMPROVE: added parameter `row.names = FALSE`in `print.Node()` to hide row numbers when printing a data.tree.

## Version 1.0.0
- IMPROVE: Replaced dependency on stringr by dependency on stringi, which make data.tree even more light-weight
- CHANGE: Node serialization changed. In many cases, you might still be able to load previously saved data.tree objects, but then they do not correspond to the latest version.
Expand Down
15 changes: 13 additions & 2 deletions R/data.tree.R → R/data.tree-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,17 @@
#' For more specialized conversions, see \code{\link{as.dendrogram.Node}}, \code{\link{as.Node.dendrogram}},
#' \code{\link{as.phylo.Node}} and \code{\link{as.Node.phylo}}
#'
#' Finally, easy conversion options from and to JSON, YAML, igraph, and more exist.
#' Finally, easy conversion options from and to list, dataframe, JSON, YAML, igraph, ape, rpart, party and more exist:
#'
#' \itemize{
#' \item{list: both directions}
#' \item{dataframe: both directions}
#' \item{JSON, YAML: both directions, via lists}
#' \item{igraph: from igraph to data.tree}
#' \item{ape: both directions}
#' \item{rpart: from rpart to data.tree}
#' \item{party: from party to data.tree}
#' }
#'
#' @section Node and Reference Semantics:
#'
Expand Down Expand Up @@ -93,6 +103,7 @@
#'
#' @seealso \code{\link{Node}}
#' @seealso For more details, see the \code{data.tree} vignette by running: \code{vignette("data.tree")}
#' @docType package
#' @name data.tree
#' @keywords internal
"_PACKAGE"
NULL
42 changes: 37 additions & 5 deletions R/node.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ NODE_RESERVED_NAMES_CONST <- c(
'path',
'pathString',
'position',
'printFormatters',
'Prune',
'Revert',
'RemoveAttribute',
Expand Down Expand Up @@ -138,13 +139,19 @@ Node <- R6Class("Node",
initialize=function(name, check = c("check", "no-warn", "no-check"), ...) {
if (!missing(name)) {
name <- as.character(name)
if (length(name) != 1) {
stop("Node name must be a scalar")
} else if (is.na(name)) {
stop("Node name must be a non-NA character scalar")
}
name <- CheckNameReservedWord(name, check)
private$p_name <- name
}
if (!missing(...)) {
args <- list(...)
mapply(FUN = function(arg, nme) self[[nme]] <- arg, args, names(args))
}

invisible (self)
},

Expand Down Expand Up @@ -550,7 +557,8 @@ Node <- R6Class("Node",

# End Traversal
#######################




),

Expand All @@ -563,6 +571,32 @@ Node <- R6Class("Node",
else private$p_name <- changeName(self, private$p_name, value)
},

#' @field printFormatters gets or sets the formatters used to print a \code{Node}.
#' Set this as a list to a root node.
#' The different formatters are h (horizontal), v (vertical), l (L), j (junction), and s (separator).
#' For example, you can set the formatters to \code{list(h = "\u2500" , v = "\u2502", l = "\u2514", j = "\u251C", s = " ")}
#' to get a similar behavior as in \code{fs::dir_tree()}.
#' The defaults are: \code{list(h = "--" , v = "\u00A6", l = "\u00B0", j = "\u00A6", s = " ")}
printFormatters = function(value) {
if (missing(value)) {
# if private$p_print_formatters is not set, return default
if (is.null(private$p_print_formatters)) {
pf <- list(h = "--" ,
v = "\u00A6",
l = "\u00B0",
j = "\u00A6",
s = " "
)
} else {
pf <- private$p_print_formatters
}

return (pf)
}
private$p_print_formatters <- value
},


#' @field parent Gets or sets the parent \code{Node} of a \code{Node}. Only set this if you know what you are doing, as you might mess up the tree structure!
parent = function(value) {
if (missing(value)) return (private$p_parent)
Expand Down Expand Up @@ -618,15 +652,13 @@ Node <- R6Class("Node",

#' @field fields Will be deprecated, use \code{attributes} instead
fields = function() {
print("Node$fields will be deprecated in the next release. Please use Node$attributes instead.")
# .Deprecated("Node$attributes", old = "Node$fields")
.Deprecated("Node$attributes", old = "Node$fields")
return(self$attributes)
},

#' @field fieldsAll Will be deprecated, use \code{attributesAll} instead
fieldsAll = function() {
print("Node$fieldsAll will be deprecated in the next release. Please use Node$attributesAll instead.")
# .Deprecated("Node$attributesAll", old = "Node$fieldsAll")
.Deprecated("Node$attributesAll", old = "Node$fieldsAll")
return(self$attributesAll)
},

Expand Down
15 changes: 7 additions & 8 deletions R/node_actives.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ isNotLeaf <- function(node) {
}



changeName <- function(node, oldName, newName) {
if(!isRoot(node)) {
rm(list = oldName, envir = node$parent)
Expand All @@ -47,27 +46,27 @@ changeName <- function(node, oldName, newName) {
return (newName)
}


#' @export
.separator <- function(self) {
if (isRoot(self)) return("")
if (self$position == self$parent$count) mySeparator <- paste0(" ", "\u00B0", "--")
else mySeparator <- paste0(" ", "\u00A6", "--")
if (self$position == self$parent$count) mySeparator <- paste0(self$root$printFormatters$s, self$root$printFormatters$l, self$root$printFormatters$h)
else mySeparator <- paste0(self$root$printFormatters$s, self$root$printFormatters$j, self$root$printFormatters$h)
return (paste0(.parentSeparator(self$parent), mySeparator))
}

#' @export
.parentSeparator <- function(self) {
if (isRoot(self)) return("")
if (self$position == self$parent$count) mySeparator <- " "
else mySeparator <- paste0(" ", "\u00A6", " ")

if (self$position == self$parent$count) mySeparator <- paste0(rep(self$root$printFormatters$s, 4), collapse = "")
else mySeparator <- paste0(self$root$printFormatters$s, self$root$printFormatters$v, self$root$printFormatters$s, self$root$printFormatters$s)
paste0(.parentSeparator(self$parent), mySeparator)

}

#' Calculate the average number of branches each non-leaf has
#'
#' @param node The node
#' @param node The node to calculate the average branching factor for
#' @export
averageBranchingFactor <- function(node) {
t <- Traverse(node, filterFun = isNotLeaf)
Expand Down
15 changes: 10 additions & 5 deletions R/node_conversion_list.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#' @param childrenName The name of the element that contains the child list (applies to mode 'explicit' only).
#' @param nodeName A name suggestion for x, if the name cannot be deferred otherwise. This is for example the case for
#' the root with mode explicit and named lists.
#' @param interpretNullAsList If \code{TRUE}, then \code{NULL}-valued lists are interpreted as child nodes. Else, they are interpreted as attributes.
#' This has only an effect if \code{mode} is "simple".
#' @param ... Any other argument to be passed to generic sub implementations
#'
#' @examples
Expand Down Expand Up @@ -57,7 +59,7 @@
#' @family as.Node
#'
#' @export
as.Node.list <- function(x, mode = c("simple", "explicit"), nameName = "name", childrenName = "children", nodeName = NULL, check = c("check", "no-warn", "no-check"), ...) {
as.Node.list <- function(x, mode = c("simple", "explicit"), nameName = "name", childrenName = "children", nodeName = NULL, interpretNullAsList = FALSE, check = c("check", "no-warn", "no-check"), ...) {
mode <- mode[1]
check <- check[1]

Expand Down Expand Up @@ -120,7 +122,10 @@ as.Node.list <- function(x, mode = c("simple", "explicit"), nameName = "name", c

#children
if (is.character(x)) return (n)
if (mode == 'simple') children <- x[vapply(x, is.list, logical(1))]
if (mode == 'simple') {
if (interpretNullAsList) children <- x[vapply(x, function(y) is.list(y) || is.null(y), logical(1))]
else children <- x[vapply(x, is.list, logical(1))]
}
else if (mode == 'explicit') children <- x[[childrenName]]

if (length(children) == 0) return (n)
Expand All @@ -138,7 +143,7 @@ as.Node.list <- function(x, mode = c("simple", "explicit"), nameName = "name", c
if (nchar(childName) == 0) childName <- i
child <- children[[i]]

childNode <- as.Node.list(child, mode, nameName, childrenName, nodeName = childName, check = check, ...)
childNode <- as.Node.list(child, mode, nameName, childrenName, nodeName = childName, interpretNullAsList = interpretNullAsList, check = check, ...)
n$AddChildNode(childNode)

}
Expand All @@ -164,8 +169,8 @@ FromListExplicit <- function(explicitList, nameName = "name", childrenName = "ch
#' interpreted as a child \code{Node}
#'
#' @export
FromListSimple <- function(simpleList, nameName = "name", nodeName = NULL, check = c("check", "no-warn", "no-check")) {
as.Node.list(simpleList, mode = "simple", nameName = nameName, nodeName = nodeName, check = check)
FromListSimple <- function(simpleList, nameName = "name", nodeName = NULL, interpretNullAsList = FALSE, check = c("check", "no-warn", "no-check")) {
as.Node.list(simpleList, mode = "simple", nameName = nameName, nodeName = nodeName, interpretNullAsList = interpretNullAsList, check = check)
}


Expand Down
5 changes: 3 additions & 2 deletions R/node_methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#' everywhere in the tree, according to their level. If pruneFun is provided, then pruneMethod is ignored.
#' @param limit The maximum number of nodes to print. Can be \code{NULL} if the
#' entire tree should be printed.
#' @param row.names If \code{TRUE} (default), then the row names are printed out. Else, they are not.
#'
#' @inheritParams ToDataFrameTree
#'
Expand All @@ -38,7 +39,7 @@
#'
#'
#' @export
print.Node <- function(x, ..., pruneMethod = c("simple", "dist", NULL), limit = 100, pruneFun = NULL) {
print.Node <- function(x, ..., pruneMethod = c("simple", "dist", NULL), limit = 100, pruneFun = NULL, row.names = T) {
if (length(pruneFun) > 0) pruneMethod <- NULL
pruneMethod <- pruneMethod[1]
if (length(pruneMethod) > 0 && length(limit) > 0) {
Expand All @@ -56,7 +57,7 @@ print.Node <- function(x, ..., pruneMethod = c("simple", "dist", NULL), limit =
}

df <- ToDataFrameTree(x, format = TRUE, ..., pruneFun = pruneFun)
print(df, na.print = "")
print(df, na.print = "", row.names = row.names)
}


Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ CRAN: [![CRAN Version](http://www.r-pkg.org/badges/version/data.tree)](https://c

Master: [![Build Status master](https://travis-ci.org/gluc/data.tree.svg?branch=master)](https://travis-ci.org/gluc/data.tree) [![Windows Build status]( https://ci.appveyor.com/api/projects/status/github/gluc/data.tree?branch=master&svg=true)](https://ci.appveyor.com/project/gluc/data.tree) [![codecov.io](http://codecov.io/github/gluc/data.tree/coverage.svg?branch=master)](http://codecov.io/github/gluc/data.tree?branch=master)

Dev: [![Build Status dev](https://travis-ci.org/gluc/data.tree.svg?branch=dev)](https://travis-ci.org/gluc/data.tree) [![Windows Build status]( https://ci.appveyor.com/api/projects/status/github/gluc/data.tree?branch=dev&svg=true)](https://ci.appveyor.com/project/gluc/data.tree) [![codecov.io](http://codecov.io/github/gluc/data.tree/coverage.svg?branch=dev)](http://codecov.io/github/gluc/data.tree?branch=dev)
<!-- badges: start -->
[![R-CMD-check](https://github.com/gluc/data.tree/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/gluc/data.tree/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->


# data.tree
An R package to manage hierarchical data and tree structures
Expand Down
Binary file modified data/acme.rda
Binary file not shown.
Binary file modified data/mushroom.rda
Binary file not shown.
1 change: 1 addition & 0 deletions data_gen/mushroom.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ points <- c('yes', 'no', 'yes', 'no', 'no')
edible <- c('toxic', 'edible', 'edible', 'edible', 'edible')
mushroom <- data.frame(color = color, size = size, points = points, edibility = edible)
save(mushroom, file = "data/mushroom.rda", compress = "xz")

15 changes: 15 additions & 0 deletions getting-started-with-development.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Dev Guide

To develop on a new environment, you need to:

1. pull from CRAN (dev branch)
2. install R
3. install RStudio
4. install RTools (https://cran.rstudio.com/bin/windows/Rtools/)
4. install tinytex
1. install.packages('tinytex')
2. tinytex::install_tinytex()
3. tinytex:::install_yihui_pkgs()
5. re-start RStudio
6. install devtools by running `install.packages("devtools")`

2 changes: 1 addition & 1 deletion man/NODE_RESERVED_NAMES_CONST.Rd

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

Loading

0 comments on commit 808dd38

Please sign in to comment.