Description Usage Arguments Details Value Examples
Get attribute values from the descendants (acropetal).
1 2 3 4 5 6 7 8 9 10 11 |
attribute |
Any node attribute (as a character) |
node |
The MTG node |
scale |
An integer vector for filtering descendant by their |
symbol |
A character vector for filtering the names of the descendant |
link |
A character vector for filtering the |
continue |
Boolean. If |
self |
Return the value of the current node ( |
filter_fun |
Any filtering function taking a node as input, e.g. |
recursivity_level |
The maximum number of recursions allowed (considering filters). E.g. to get only the
children, |
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).
The attribute values from the descendant(s) of the node
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | filepath= system.file("extdata", "tree1h.mtg", package = "XploRer")
MTG = read_mtg(filepath)
node_8 = extract_node(MTG,"node_8")
# getting all descendants of node_8
descendants(attribute = "length", node = node_8)
# getting all descendants of node_8, but only the nodes with symbol "S":
descendants(attribute = "length", node = node_8, symbol = "S")
# getting all descendants of node_8, but only the nodes with symbol "S", and not
# recursively, i.e. we stop the search for a child if it is filtered out (we don't
# go to its own children)
descendants(attribute = "length", node = node_8, symbol = "S",
continue = FALSE)
# getting the children of node_8 (and not below):
descendants(attribute = "length", node = node_8, recursivity_level = 1)
# getting the children of node_8 and their children:
descendants(attribute = "length", node = node_8, recursivity_level = 2)
# getting the children of node_8 and their children, and filter for "S":
descendants(attribute = "length", node = node_8, symbol = "S", recursivity_level = 2)
# The function returns until node_12 because node_10 is not an "S" and is then filtered out
# which makes node_12 two levels below node.
# To get the descendants of a node but only for the nodes following it, not
# branching (e.g. for an axis):
descendants(attribute = "length", node = node_8, symbol = "S",
link = c("/","<"), continue = FALSE)
# To get the values for the leaves (i.e. the terminal node) only:
descendants(attribute = "length", node = node_8, filter_fun = data.tree::isLeaf)
# Note: prefer using leaves() instead as it takes scales into account.
# Length were observed at the "S" scale (S = segment of an axis between two branches),
# but we need the length at the axis scale, to do so:
mutate_mtg(MTG,
axis_length = sum(descendants(attribute = "length", symbol = "S",
link = c("/","<"), continue = FALSE)),
.symbol = "A")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.