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.

News

All changes to data.tree are documented here.

  • ADD: new Distance function to measure distance from one Node to another in the same tree
  • IMPROVE: FromListSimple now accepts subclasses of lists (#79)
  • IMPROVE: FromDataFrameTable now supports tibbles (#89)
  • IMPROVE: print.Node and as.data.frame.Node now also work for node fields with length > 1 (#81)
  • FIX: print.Node and as.data.frame.Node 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
  • IMPROVE: Performance improvement for many functions. For example, as.Node roughly by factor 4 for large dataset (#74)
  • CHANGE: by default, as.data.frame.Node (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)
  • IMPROVE: as.Node.data.frame 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)
  • 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: as.Node.party Convert party class from partykit package to data.tree (#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)
  • FIX: minor correction in documentation
  • FIX: minor correction in documentation
  • 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
  • ADD: FromListExplicit now interprets character vectors as a list of nodes (#58)
  • 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)
  • 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)
  • FIX: applications vignette, changed from http://htmlwidgets.org to http://www.htmlwidgets.org, as requested by CRAN
  • 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
  • FIX: Get can now fetch vectors and matrices too
  • ADD: Node$siblings
  • 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)
  • Set correct version number in DESCRIPTION file
  • 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
  • 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.

install.packages("data.tree")

0.7.3 by Christoph Glur, 12 days ago


http://github.com/gluc/data.tree


Report a bug at http://github.com/gluc/data.tree/issues


Browse source code at https://github.com/cran/data.tree


Authors: 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, stringr, methods, DiagrammeR

Suggests Formula, graphics, testthat, knitr, ape, yaml, networkD3, jsonlite, igraph, treemap, party, partykit, doParallel, foreach, htmlwidgets


Imported by SACCR, ahp, collapsibleTree, hypoparsr, nonlinearICP, prof.tree, radiant.model, stoRy, userfriendlyscience.

Suggested by Rodam, tidygraph.


See at CRAN