children: Get children values

Description Usage Arguments Details Value Examples

View source: R/mtg_getters_shortcuts.R

Description

Get attribute values from the children of a node.

Usage

1
2
3
4
5
6
7
8
9
children(
  attribute,
  node = NULL,
  scale = NULL,
  symbol = NULL,
  link = NULL,
  filter_fun = NULL,
  continue = TRUE
)

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, e.g. data.tree::isLeaf()

continue

If a child is not of the right scale, continue until the scale required is met if TRUE, or returns NA if FALSE.

Details

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

Value

The attribute values from the children of the node

Examples

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

VEZY/XploRer documentation built on Oct. 9, 2021, 10:05 p.m.