View source: R/node_methods_traversal.R
Get | R Documentation |
The Get
method is one of the most important ones of the data.tree
package. It lets you traverse a tree
and collect values along the way. Alternatively, you can call a method or a function on each Node
.
# OO-style:
#node$Get(attribute,
# ...,
# traversal = c("pre-order", "post-order", "in-order", "level", "ancestor"),
# pruneFun = NULL,
# filterFun = NULL,
# format = FALSE,
# inheritFromAncestors = FALSE)
# traditional:
Get(nodes,
attribute,
...,
format = FALSE,
inheritFromAncestors = FALSE,
simplify = c(TRUE, FALSE, "array", "regular"))
nodes |
The nodes on which to perform the Get (typically obtained via |
attribute |
determines what is collected. The
|
... |
in case the |
format |
if |
inheritFromAncestors |
if |
simplify |
same as |
a vector containing the atrributes
collected during traversal, in traversal order. NULL
is converted
to NA, such that length(Node$Get) == Node$totalCount
Node
Set
Do
Traverse
data(acme)
acme$Get("level")
acme$Get("totalCount")
acme$Get(function(node) node$cost * node$p,
filterFun = isLeaf)
#This is equivalent:
nodes <- Traverse(acme, filterFun = isLeaf)
Get(nodes, function(node) node$cost * node$p)
#simplify = "regular" will preserve names
acme$Get(function(x) c(position = x$position, level = x$level), simplify = "regular")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.