Get attribute values from the terminal nodes of the descendants sub-tree of a node (i.e. the "leaves" in computer science terms).
leaves( attribute, node = NULL, scale = NULL, symbol = NULL, link = NULL, filter_fun = NULL )
attribute | Any node attribute (as a character) |
---|---|
node | The MTG node |
scale | An integer vector for filtering the |
symbol | A character vector for filtering the children by the name of their |
link | A character vector for filtering the |
filter_fun | Any filtering function taking a node as input. |
The attribute values from the children of the node
This function is mainly intended to be used with mutate_mtg()
. In this case,
the node
argument can be left empty (or you can put node = node
equivalently).
#> Warning: the condition has length > 1 and only the first element will be used#> Warning: the condition has length > 1 and only the first element will be used#> Warning: the condition has length > 1 and only the first element will be used#> Warning: the condition has length > 1 and only the first element will be used# The MTG has two leaves (node_5 and node_7): leaves("Length", node = MTG)#> node_5 node_7 #> 10 12# We can check the function worked well by printing the symbols of each nodes: print(MTG, ".symbol")#> levelName .symbol #> 1 node_1 Scene #> 2 °--node_2 Individual #> 3 °--node_3 Axis #> 4 °--node_4 Internode #> 5 ¦--node_5 Leaf #> 6 °--node_6 Internode #> 7 °--node_7 Leaf# If we need the terminal Internodes: leaves("Length", node = MTG, symbol = "Internode")#> node_6 #> 6#> levelName .scale #> 1 node_1 NA #> 2 °--node_2 1 #> 3 °--node_3 2 #> 4 °--node_4 3 #> 5 ¦--node_5 3 #> 6 °--node_6 3 #> 7 °--node_7 3leaves("Length", node = MTG, scale = 2)#> node_3 #> NA