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
)

Arguments

attribute

Any node attribute (as a character)

node

The MTG node

scale

An integer vector for filtering the .scale of the children (i.e. the SCALE column from the MTG classes).

symbol

A character vector for filtering the children by the name of their .symbol (i.e. the SYMBOL column from the MTG classes).

link

A character vector for filtering the .link with the children

filter_fun

Any filtering function taking a node as input.

Value

The attribute values from the children of the node

Note

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).

Examples

filepath= system.file("extdata", "simple_plant.mtg", package = "XploRer") MTG = read_mtg(filepath)
#> 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
# Or the leaves at a given scale: print(MTG, ".scale")
#> 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 3
leaves("Length", node = MTG, scale = 2)
#> node_3 #> NA