Get attribute values from all ancestors (basipetal).
ancestors( attribute, node = NULL, scale = NULL, symbol = NULL, link = NULL, filter_fun = NULL, self = FALSE, continue = TRUE, recursivity_level = NULL )
attribute | Any node attribute (as a character) |
---|---|
node | The MTG node |
scale | Integer vector for filtering ancestors by their |
symbol | A character vector for filtering the ancestors by their |
link | A character vector for filtering the |
filter_fun | Any filtering function taking a node as input, e.g. |
self | Return the value of the current node ( |
continue | Boolean. If |
recursivity_level | The maximum number of recursions allowed (considering filters). E.g. to get the
parent only: |
The attribute values from the ancestors of the node (from first parent to farther ancestor)
This function is mainly intended to be used with mutate_mtg()
. In this case,
the node
argument can be left empty (or 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#> node_4 node_3 node_2 node_1 #> 4 NA NA NA# Two of them have no values for Length # If the value of node_6 is also needed: ancestors("Length", node = extract_node(MTG, "node_6"), self = TRUE)#> node_6 node_4 node_3 node_2 node_1 #> 6 4 NA NA NA# If we only need the value of the first parent: ancestors("Length", node = extract_node(MTG, "node_6"), recursivity_level = 1)#> node_4 #> 4# We can filter by symbol if we need to return the values for some symbols only: ancestors("Width", node = extract_node(MTG, "node_6"), symbol = "Internode")#> node_4 #> 1# The values are only returned for the ancestors with the required symbol # For example we know that a leaf cannot be an ancestor because it cannot bear anything: ancestors("Width", node = extract_node(MTG, "node_6"), symbol = "Leaf")#> logical(0)# In this case it returns a length 0 vector.