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
.
Traverse(
node,
traversal = c("pre-order", "post-order", "in-order", "level", "ancestor"),
pruneFun = NULL,
filterFun = NULL
)
a list of Node
s
the root of a tree or a sub-tree that should be traversed
any of 'pre-order' (the default), 'post-order', 'in-order', 'level', 'ancestor', or a custom function (see details)
allows providing a prune criteria, i.e. a function taking a Node
as an input, and returning TRUE
or FALSE
.
If the pruneFun returns FALSE for a Node, then the Node and its entire sub-tree will not be considered.
allows providing a a filter, i.e. a function taking a Node
as an input, and returning TRUE
or FALSE
.
Note that if filter returns FALSE
, then the node will be excluded from the result (but not the entire subtree).
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).
Go to first child, then to its first child, etc.
Go to the first branch's leaf, then to its siblings, and work your way back to the root
Go to the first branch's leaf, then to its parent, and only then to the leaf's sibling
Collect root, then level 2, then level 3, etc.
Take a node, then the node's parent, then that node's parent in turn, etc. This ignores the pruneFun
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.
Node
Get
Set
Do