Traverse {data.tree} | R Documentation |
Traverse a tree or a sub-tree
Description
Traverse takes the root of a tree or a sub-tree, and "walks" the tree in a specific order. It returns a list of
Node
objects, filtered and pruned by filterFun
and pruneFun
.
Usage
Traverse(
node,
traversal = c("pre-order", "post-order", "in-order", "level", "ancestor"),
pruneFun = NULL,
filterFun = NULL
)
Arguments
node |
the root of a tree or a sub-tree that should be traversed |
traversal |
any of 'pre-order' (the default), 'post-order', 'in-order', 'level', 'ancestor', or a custom function (see details) |
pruneFun |
allows providing a prune criteria, i.e. a function taking a |
filterFun |
allows providing a a filter, i.e. a function taking a |
Details
The traversal order is as follows. (Note that these descriptions are not precise and complete. They are meant for quick reference only. See the data.tree vignette for a more detailed description).
- pre-order
Go to first child, then to its first child, etc.
- post-order
Go to the first branch's leaf, then to its siblings, and work your way back to the root
- in-order
Go to the first branch's leaf, then to its parent, and only then to the leaf's sibling
- level
Collect root, then level 2, then level 3, etc.
- ancestor
Take a node, then the node's parent, then that node's parent in turn, etc. This ignores the
pruneFun
- function
You can also provide a function, whose sole parameter is a
Node
object. The function is expected to return the node's next node, a list of the node's next nodes, or NULL.
Value
a list of Node
s