CI Tool Status for Master Status for Develop
Travis Build Status Build Status
AppVeyor AppVeyor Build Status AppVeyor Build Status
Codecov Coverage Status Coverage Status
Coveralls Coverage Status Coverage Status

Apache License


This R package allows you to create trees with an arbitrary number of child nodes per parent node. It includes an depth first iterator, a function to plot the tree and a function to print the tree.

The current main benefit is that it allows to convert a R parsed object to a tree.


General use

# Initialize the tree.
tree <- GeneralTree$new('root', '1.1')

# Add nodes.
tree$addNode('root', 'child1', '2.1')
tree$addNode('root', 'child2', '2.2')
tree$addNode('root', 'child3', '2.3')

# Print the tree

The output would be:

root : 1.1 --> child1 : 2.1
           |-> child2 : 2.2
           \-> child3 : 2.3


There are two ways to iterate through the tree depth first. The first uses an internal mechanism whereas the second allows the data structure to be hooked in the foreach and iterator packages.


The benefit of this approach is that you do not require dependencies on foreach and iterator.

i <- tree$iterator()
while (!is.null(i)) {
    i <- tryCatch(i$nextElem(), error = function(e) NULL)


Using the foreach and iterator packages permits you to write shorter code, as the following example shows:

itx <- iter(tree, by = "id")
numbers_in_tree <- foreach(i = itx, .combine = c) %do% c(i)

Note that the package has not yet been tested in a parallel environment.

How to install

The easiest way to install the package is by means of the devtools,

install_github('GeneralTree', username = 'abossenbroek')


The GeneralTree package is licensed under the Apache V2.0 license.