Description Usage Arguments Details Value Examples
View source: R/mtg_getters_shortcuts.R
Get attribute values from the children of a node.
1 2 3 4 5 6 7 8 9 |
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, e.g. |
continue |
If a child is not of the right |
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 children 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 | filepath= system.file("extdata", "simple_plant.mtg", package = "XploRer")
MTG = read_mtg(filepath)
# node_6 has one child:
children("Length", node = extract_node(MTG, "node_6"))
# Using node 4 as reference now:
node_4 = extract_node(MTG, "node_4")
# node_4 has two children, returns two values:
children("Length", node = node_4)
# To get the names of those children:
children("name", node = node_4)
# The width is not available for one child ("node_6"):
children("Width", node = node_4)
# We can filter by scale if we need to return the values for some scales only:
children("Width", node = node_4, symbol = "Leaf")
# Here we get the value of node_7 also, because its parent "node_6" is not of scale
# "Leaf", so it was filtered out. It you need the values for one scale, but not
# making a recursive search from one scale to another until finding the required scale,
# you can put the `continue` argument to `FALSE`:
children("Width", node = node_4, symbol = "Leaf", continue = FALSE)
# To get the values of the children of each node:
mutate_mtg(MTG, children_width = children("Width"))
print(MTG, "Width", "children_width")
# And using only the bodes with symbol "Leaf":
mutate_mtg(MTG, children_width2 = children("Width", symbol = "Leaf", continue = FALSE))
print(MTG, "Width", "children_width2")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.