ancestors: Get ancestors values

Description Usage Arguments Details Value Examples

View source: R/ancestors.R

Description

Get attribute values from all ancestors (basipetal).

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
ancestors(
  attribute,
  node = NULL,
  scale = NULL,
  symbol = NULL,
  link = NULL,
  filter_fun = NULL,
  self = FALSE,
  continue = TRUE,
  recursivity_level = NULL
)

Arguments

attribute

Any node attribute (as a character)

node

The MTG node

scale

Integer vector for filtering ancestors by their .scale (i.e. the SCALE from the MTG classes).

symbol

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

link

A character vector for filtering the .link with the parent (e.g. not a branch)

filter_fun

Any filtering function taking a node as input, e.g. data.tree::isLeaf()

self

Return the value of the current node (TRUE), or the ancestors only (FALSE, the default)

continue

Boolean. If TRUE, the function returns all nodes that are not filtered. If FALSE, stop at the first node that is filtered out.

recursivity_level

The maximum number of recursions allowed (considering filters). E.g. to get the parent only: recursivity_level = 1, for parent + grand-parent: recursivity_level = 2. If NULL (the default), the function returns all values from the node to the root.

Details

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

Value

The attribute values from the ancestors of the node (from first parent to farther ancestor)

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
filepath= system.file("extdata", "simple_plant.mtg", package = "XploRer")
MTG = read_mtg(filepath)

# node_6 has four ancestors:
ancestors("Length", node = extract_node(MTG, "node_6"))
# 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)

# If we only need the value of the first parent:
ancestors("Length", node = extract_node(MTG, "node_6"), recursivity_level = 1)

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

# 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")
# In this case it returns a length 0 vector.

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