data.tree
Structure With Nodes
Node
is at the very heart of the data.tree
package. All trees are constructed
by tying toghether Node
objects.
Node
An R6Class
generator object
children
A list of child Nodes
parent
The 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 name
s of the Node
s, 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 = TRUE
Sort 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
name
Gets or sets the name of a Node
. For example Node$name <- "Acme"
fields
Gets the names of the set properties of a Node
fieldsAll
Gets the names of the set properties of a Node
or any of its sub-Nodes
isLeaf
Returns TRUE
if the Node
is a leaf, FALSE
otherwise
isRoot
Returns TRUE
if the Node
is the root, FALSE
otherwise
count
Returns the number of children of a Node
totalCount
Returns the total number of Node
s in the tree
path
Returns a vector of mode character
containing the names of the Node
s in the path from the root to this Node
pathString
Returns a string representing the path to this Node
, separated by backslash
levelName
Returns the name of the Node
, preceded by level times '*'. Useful for printing.
leafCount
Returns the number of leaves are below a Node
leaves
Returns a list containing all the leaf Node
s
level
Returns an integer representing the level of a Node
. For example, the root has level 0.
height
Returns max(level) of any of the Nodes
of the tree
averageBranchingFactor
Returns the average number of crotches below this Node
root
Returns 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