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.

An R package to manage hierarchical data and tree structures

data.tree is to hierarchical data what data.frame is to tabular data. You can create tree structures from hierarchical data, and use the utility methods to traverse the tree in various orders. You can also aggregate, print, convert to and from data.frame, and apply functions to your tree data.


All changes to data.tree are documented here.

Version 0.7.8

  • FIX: wrong export of S3

Version 0.7.7

  • IMPROVE: if an attribute of a node has n dimensions, then Get will return an array of dim n+1, with the names of the first dimension being equal to the node names (thanks to Chris Hammil)
  • FIX: fieldsAll now doesn't simplify (thanks to Vaclav Slimacek)

Version 0.7.6

  • IMPROVE: plot now also works for trees with a single root node (thx to Pierre Neuvial)
  • IMPROVE: ellipsis parameters are not passed to DiagrammeR for plotting (#109)
  • FIX: Dependency on DiagrammeR (>= 1.0.0) explicitly stated (#111)
  • IMPROVE: Allow tibble in FromDataFrameNetwork and FromDataFrameTable (#115)

Version 0.7.5

  • IMPROVE: namesNotUnique parameter in as.Node.phylo (#106)
  • FIX: fixed incompatibility issue with DiagrammeR (#110)

Version 0.7.4

  • IMPROVE: print now has an explicit arg pruneFun
  • FIX: partykit tests now pass
  • FIX: DESCRIPTION now in line with latest changes from CRAN (rmarkdown declared)
  • FIX: Skipped tests in testMethods included

Version 0.7.3

  • FIX: Various typos in documentation

Version 0.7.2

Upgrade to R 3.4.x and newest package versions.

  • FIX: plot: global graph attributes now work (#88)
  • FIX: typo in vignette data.tree vignette('applications', package = "data.tree")
  • FIX: warnings in as.dendrogram
  • FIX: warnings in sample code for Do
  • FIX: created warnings for values that were of length 0

Version 0.7.0

  • ADD: ToDiagrammeRGraph to convert to a DiagrammeR graph object
  • REMOVE: ToGraphViz (replaced with ToDiagrammeRGraph, to support the latest features in the DiagrammeR package). You can still get the dot representation by using DiagrammeR::generate_dot(ToDiagrammeRGraph(node))
  • CHANGE: plot.Node 's last parameter is now 'graph', and not 'engine' anymore.
  • FIX: minor typos fixed

Version 0.6.2

  • ADD: new Distance function to measure distance from one Node to another in the same tree

Version 0.6.1

  • IMPROVE: FromListSimple now accepts subclasses of lists (#79)
  • IMPROVE: FromDataFrameTable now supports tibbles (#89)
  • IMPROVE: print.Node and now also work for node fields with length > 1 (#81)
  • FIX: print.Node and now also work if some Nodes have the same name as some fileds (#82)
  • REMOVE: node$FindNode, and node$Navigate are now deprecated. Use FindNode(node, ...) and Naviate(node, ...) instead
  • REMOVE: node$Sort, node$Prune, and node$Revert are now deprecated. Use Sort(node, ...), Prune(node, ...) and Revert(node, ...) instead

Version 0.5.0

  • IMPROVE: Performance improvement for many functions. For example, as.Node roughly by factor 4 for large dataset (#74)
  • CHANGE: by default, (and derivatives) do not format anymore (use the format parameter if you want to format)
  • IMPROVE: Allow the possibility to keep only some fields when converting to list using as.list.Node (#76)
  • FromDataFrameTable (#77)
    • FIX: now also works if there is only the pathString column
    • IMPROVE: pathString can now also be a factor (or any other type convertible to character)

Version 0.4.0

  • IMPROVE: and FromDataFrameTable now support paths containing reserved words (#65)
  • CHANGE: Node$new now checks that names are not reserved names. As a consequence, many conversions to Node now contain a check parameter.
  • IMPROVE: Climb is now much faster when climbing by name (#71)
  • IMPROVE: As a result of #71, many other functions are much faster, e.g. FromDataFrameTable (#72)

Version 0.3.7

  • ADD: Traverse can now also take custom function as a traversal argument
  • ADD: Navigate method
  • ADD: as.Node.BinaryTree Convert SplittingNode from party package to data.tree (#6)
  • ADD: Convert party class from partykit package to data.tree (#6)

Version 0.3.6

  • FIX: GetDefaultTooltip now also works for attributes which are functions
  • FIX: GetAttribute now returns attributes with length 0 (e.g. an empty list)
  • ADD: Sort, Revert and Prune are now also available in traditional format (e.g. Prune(node, pruneFun))
  • FIX: FromListSimple: Empty lists now become empty nodes (#59)
  • IMPROVE: FromListSimple: Unnamed list elements are now also converted (#61)
  • IMPROVE: documentation of Aggregate
  • IMPROVE: Check type when setting Node$parent and Node$children (#63)

Version 0.3.5

  • FIX: minor correction in documentation

Version 0.3.4

  • FIX: minor correction in documentation

Version 0.3.3

  • CHANGE: Renamed Find method to FindNode, in order to avoid masking from base
  • FIX: upgrade to latest version of treemap package
  • FIX: a few typos in documentation

Version 0.3.2

  • ADD: FromListExplicit now interprets character vectors as a list of nodes (#58)

Version 0.3.1

  • IMPROVE: as.list.Node
    • now generates auto name if unique name is not available (#54)
    • now has warn arg, warning if source data contains reserved names
    • now also imports fiels with names equal to reserved names (e.g. count), they will be renamed (to e.g. count2)
  • CHANGE: node$leaves now returns a list even when called on a leaf itself
  • ADD: Find method to find a single Node in a (sub-)tree (#52)

Version 0.3.0 Pine Tree

  • REMOVE: Removed the cacheAttribute parameter from Aggregate and Cumulate (they were confusing, even to me. Use Do instead to manually store aggregate values in the tree)
  • ADD: plot function (see ?plot.Node)
  • ADD: ToDataFrameTypeCol to export e.g. the path to columns by level in columns: ToDataFrameTypeCol(acme)
  • ADD: Node$AddSibling
  • ADD: Node$RemoveAttribute now contains a mandatory parameter so that it can be used if the node does not have the attribute to be removed.
  • ADD: Get works on methods without args
  • IMPROVE: FormatFixedDecimal and FormatPercent work for NULL values
  • IMPROVE: Documentation
  • FIX: Aggregate will not return attribute from callee anymore, but always aggregate children attributes
  • FIX: Removed ... parameter from ToListExplicit and ToListSimple
  • FIX: Clone was adding empty children list, which caused a series of problems (#44)
  • FIX: Cloning a subtree does not keep reference to un-cloned parent anymore (#49)
  • FIX: print with limit parameter ignored formatter (#43)
  • FIX: cannot rename to int, e.g. acme$Do(function(x) x$name <- x$position) (#53)

Version 0.2.4

Version 0.2.3

  • FIX #33: applications vignette doesn't build because of DiagrammeR update
  • FIX #32: Cannot subclass Node
  • FIX #30: strange errors when using data.tree multiple times

Version 0.2.2

  • FIX: Get can now fetch vectors and matrices too
  • ADD: Node$siblings

Version 0.2.0-rc.1 Elder

  • ADD: ClimbByAttribute
  • FIX: Aggregate and Cumulate now work always on attributes having a formatter
  • ADD: as.igraph now has a 'directed' parameter
  • ADD: print now has a pruneMethod, allowing different methods to avoid that a huge tree is printed to the console
  • REMOVE: FromDataFrameTaxonomy and ToDataFrameTaxonomy (replaced by FromDataFrameNetwork and ToDataFrameNetwork, but with some differences)
  • ADD: FromDataFrameNetwork and ToDataFrameNetwork
  • IMPROVE: make Traversal "level" much faster
  • ADD: Node$RemoveChild
  • ADD: Node$RemoveAttribute
  • ADD: as.igraph.Node now supports different directions (climb and descend)

Version 0.1.9 Pine II

  • Set correct version number in DESCRIPTION file

Version 0.1.8 Pine

  • Node
    • CHANGE: Node$depth is now called Node$height, as the old naming was confusing for many, because in CS, the Node$level is sometimes
  • Utils
    • CHANGE: Renamed CreateDummyTree to CreateRegularTree
    • CHANGE: Height renamed to DefaultPlotHeight, so as to avoid confusion with Node$height
    • ADD: CreateRandomTree to test trees
    • ADD: trees can now be climbed directly, e.g. acme$IT$Go agile
    • ADD: print.Node with limit parameter is now much faster
    • ADD: Clone is now much faster

Version 0.1.7 Chestnut

  • General
    • ADD: demo portfolio
    • ADD: demo decisiontree
    • ADD: demo population / treemap
  • Node
    • CHANGE: Node$level is now 1-based (used to be: 0-based), i.e. if Node$isRoot then Node$level = 1
    • CHANGE: Node$Find is now called Node$Climb to avoid confusion with base::Find called depth
    • ADD: print.Node contains a limit parameter, allowing to limit the max number of Nodes to be printed
    • ADD: Clone (returning a deep copy)
    • ADD: Prune (pruning the tree)
    • ADD: SetFromat (support for setting formatter functions on a Node)
    • ADD: Traverse, standalone traverse method that can be used for piping and whenever you need to apply multiple Get/Set/Do on the same traversal
    • ADD: Node$isBinary active
    • ADD: standalone versions of isLeaf, isNotLeaf, isRoot, isNotRoot for concise filtering
    • ADD: AreNamesUnique to test if names of the node's are unique throughout the tree (and not only among siblings)
    • FIX: node$position now returns 1 for root
    • ADD: Aggregate function now supports functions
    • ADD: node$averageBranchingFactor
    • CHANGE: Aggregate function does not cache anymore by default. See cacheAttribute for details.
    • Node$Get:
      • CHANGE: Renamed filterFun parameter to pruneFun
      • ADD: new parameter filterFun, as opposed to pruneFun
      • CHANGE: removed the assign parameter (use Do instead)
      • ADD: new traversal modes "in-order", "level"
      • ADD: parameter inheritFromAncestors
    • Node$Set:
      • ADD: filterFun and pruneFun
      • ADD: support for traversal order
    • Node$Do:
      • ADD: new function Do, which applies a function to Nodes
  • Conversions
    • ADD: conversion to and from list of lists (and thus to and from yaml, json, etc.)
    • ADD: conversion from data.frame
    • ADD: conversion to and from dendrogram
    • ADD: conversion to and from phylo from the ape package
    • ADD: conversion to Newick notation
    • ADD: conversion ToDataFrameTable (returning leafs only)
    • ADD: conversion ToDataFrameTree
    • ADD: conversion ToDataFrameTaxonomy
    • ADD: conversion to igraph
  • Utils
    • CHANGE: Renamed PrintFixedDecimal to FormatFixedDecimal to achieve better consistency
    • ADD: CreateDummyTree to test large trees
    • ADD: CreateRandomTree to test trees

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.


1.0.0 by Christoph Glur, a year ago

Report a bug at

Browse source code at

Authors: Russ Hyde [ctb] (improve dependencies) , Chris Hammill [ctb] (improve getting) , Facundo Munoz [ctb] (improve list conversion) , Markus Wamser [ctb] (fixed some typos) , Pierre Formont [ctb] (additional features) , Kent Russel [ctb] (documentation) , Noam Ross [ctb] (fixes) , Duncan Garmonsway [ctb] (fixes) , Christoph Glur [aut, cre] (R interface)

Documentation:   PDF Manual  

GPL (>= 2) license

Imports R6, stringi, methods

Suggests Formula, graphics, testthat, knitr, rmarkdown, ape, yaml, networkD3, jsonlite, treemap, party, partykit, doParallel, foreach, htmlwidgets, DiagrammeR, mockery, rpart

Enhances igraph

Imported by Cluster.OBeu, HCD, RFpredInterval, SACCR, TT, UniprotR, behaviorchange, changepoints, collapsibleTree, directotree, filterNHP, forestry, galah, gimme, justifier, nonlinearICP, prof.tree, radiant.model, randomForestSRC, rocTree, rock, starvz, voronoiTreemap, webchem.

Depended on by GE, GeoFIS, nmarank, pmxTools, triversity.

Suggested by DataPackageR, NMproject, Rodam, covid19dbcand, echarts4r, iconr, magclass, momentuHMM, styler, tidygraph, wrMisc, wrTopDownFrag, yum.

See at CRAN