data.tree v0.7.0

by Christoph Glur

General Purpose Hierarchical Data Structure

Create tree structures from hierarchical data, and traverse the tree in various orders. Aggregate, cumulate, print, plot, convert to and from data.frame and more. Useful for decision trees, machine learning, finance, conversion from and to JSON, and many other applications.


CRAN: CRAN Version CRAN downloads

Master: Build Status master Windows Build status

Dev: Build Status dev Windows Build status


An R package to manage hierarchical data and tree structures

Hierarchical data is ubiquitous in statistics and programming (XML, search trees, family trees, classification, file system, etc.). However, no general-use tree data structure is available in base R. Where tabular data has data.frame, hierarchical data is often modeled in lists of lists or similar makeshifts. These structures are often difficult to manage. This is where the data.tree package steps in. It lets you build trees of hierarchical data for various uses: to print, plot and visualize, to generate breakdowns, to integrate with html widgets, to rapid prototype search algorithms, to test out new classification ideas, and much more.

Tree structures can be created programmatically, or by conversion. The package provides functionality to convert from and to various formats such as data.frames, list of lists, dendrograms, partykit, ape phylo, igraph, JSON, YAML, and more.

Learn More

To get started, you might want to read the introduction vignette. There is also a vignette containing some examples and applications.

The manual is here

Finally, you'll find more examples and background information on my blog.


The latest from github dev branch may have some breaking changes compared to CRAN. See NEWS for details.


Coding Conventions: Google Style Guide, see

Versioning Conventions: SemanticVersioning. See for details

Branching Conventions: GitFlow. See

Pull Requests: Very welcome! Please branch from the dev branch.

Functions in data.tree

Name Description
as.list.Node Convert a data.tree structure to a list-of-list structure
as.Node.dendrogram Convert a dendrogram to a data.tree Node
Aggregate Aggregate child values of a Node, recursively.
acme Sample Data: A Simple Company with Departments Convert a data.frame to a data.tree structure
AreNamesUnique Test whether all node names are unique.
as.igraph.Node Convert a data.tree structure to an igraph network
as.Node.BinaryTree Convert a a SplitNode from the party package to a data.tree structure.
as.phylo.Node Convert a Node to a phylo object from the ape package.
averageBranchingFactor Calculate the average number of branches each non-leaf has
CheckNameReservedWord Checks whether name is a reserved word, as defined in NODE_RESERVED_NAMES_CONST.
Clone Clone a tree (creates a deep copy)
as.Node.list Convert a nested list structure to a data.tree structure
Climb Climb a tree from parent to children, by provided criteria.
as.Node Convert an object to a data.tree data structure Convert a a party from the partykit package to a data.tree structure.
as.Node.phylo Convert a phylo object from the ape package to a Node Convert a data.tree structure to a data.frame
Prune Prunes a tree.
Revert Reverts the sort order of a Node's children.
as.dendrogram.Node Convert a Node to a dendrogram
Distance Find the distance between two nodes of the same tree
NODE_RESERVED_NAMES_CONST Names that are reserved by the Node class.
Do Executes a function on a set of nodes
Sort Sort children of a Node or an entire data.tree structure
print.Node Print a Node in a human-readable fashion.
CreateRandomTree Create a tree for demo and testing
plot.Node Plot a graph, or get a graphviz dot representation of the tree
CreateRegularTree Create a tree for demo and testing
Cumulate Cumulate values among siblings
isLeaf Check if a Node is a leaf
Set Traverse a Tree and Assign Values
SetFormat Set a formatter function on a specific node
isNotLeaf Check if a Node is not a leaf
GetAttribute Get an attribute from a Node.
FormatFixedDecimal Format a Number as a Decimal
FindNode Find a node by name in the (sub-)tree
GetPhyloNr Determine the number a Node has after conversion to a phylo object
ToNewick Write a data.tree structure to Newick notation
Traverse Traverse a tree or a sub-tree
FormatPercent Format a Number as a Percentage
Get Traverse a Tree and Collect Values
isRoot Check if a Node is the root
DefaultPlotHeight Calculates the height of a Node given the height of the root.
data.tree data.tree: Hierarchical Data Structures
isNotRoot Check if a Node is not a root
mushroom Sample Data: Data Used by the ID3 Vignette
Navigate Navigate to another node by relative path.
No Results!


Include our badge in your README