data.tree Structure With NodesNode is at the very heart of the data.tree package. All trees are constructed
by tying toghether Node objects.
NodeAn R6Class generator object
childrenA list of child Nodes
parentThe node's parent Node
Node$new(name)Creates a new Node called name. Often used to construct the root when creating trees programmatically.
AddChild(name)Creates a new Node called name and adds it to this Node as a child.
RemoveChild(name)Remove the child Node called name from a Node and returns it.
RemoveAttribute(name)Removes attribute called name from this Node.
Climb(...)Find a node with path ..., where the ... arguments are the names of the Nodes, or other field values.
Get(attribute, ..., traversal = c("pre-order", "post-order", "in-order", "level", "ancestor"), pruneFun = NULL, filterFun = NULL, format = NULL, inheritFromAncestors = FALSE)Traverses the tree and collects values along the way.
Do(fun, ..., traversal = c("pre-order", "post-order", "in-order", "level", "ancestor"), pruneFun = NULL, filterFun = NUL)Traverses the tree and call fun on each node.
Set(..., traversal = c("pre-order", "post-order", "in-order", "level", "ancestor"), pruneFun = NULL, filterFun = NULL)Traverses the tree and assigns the args along the way, recycling the args.
Sort(attribute, ..., decreasing = FALSE, recursive = TRUESort children of a node with respect to an attribute (field, method, active, function)
Revert(recursive = TRUE)Revert the sort order of a node
Prune(pruneFun)Prune a tree. The pruneFun takes a node as its first argument, and returns TRUE if the node should be kept, FALSE otherwise
nameGets or sets the name of a Node. For example Node$name <- "Acme"
fieldsGets the names of the set properties of a Node
fieldsAllGets the names of the set properties of a Node or any of its sub-Nodes
isLeafReturns TRUE if the Node is a leaf, FALSE otherwise
isRootReturns TRUE if the Node is the root, FALSE otherwise
countReturns the number of children of a Node
totalCountReturns the total number of Nodes in the tree
pathReturns a vector of mode character containing the names of the Nodes in the path from the root to this Node
pathStringReturns a string representing the path to this Node, separated by backslash
levelNameReturns the name of the Node, preceded by level times '*'. Useful for printing.
leafCountReturns the number of leaves are below a Node
leavesReturns a list containing all the leaf Nodes
levelReturns an integer representing the level of a Node. For example, the root has level 0.
heightReturns max(level) of any of the Nodes of the tree
averageBranchingFactorReturns the average number of crotches below this Node
rootReturns the root Node of a Node's tree
For more details see the data.tree documentations, or the data.tree vignette: vignette("data.tree")
# NOT RUN {
library(data.tree)
acme <- Node$new("Acme Inc.")
accounting <- acme$AddChild("Accounting")
print(acme)
# }
Run the code above in your browser using DataLab