Build a decision tree from a hierarchical list
load_tree_node_list.Rd
Constructs a tree from a nested R list, where the hierarchy is
defined by the list's structure. It also initialises the answer
and
confidence
attributes required for the analysis.
Value
A data.tree
object, fully constructed and initialised with answer
and confidence
attributes set to NA
.
Details
This is a core constructor function, typically called by the
load_tree_yaml()
wrapper, which handles parsing the YAML file into a list.
See also
load_tree_yaml()
to read this format from a file.
Examples
# 1. Define the tree structure as a nested list
my_data_list <- list(
name = "Root",
rule = "OR",
nodes = list(
list(name = "Leaf A", question = "Is A true?"),
list(name = "Branch B",
rule = "AND",
nodes = list(
list(name = "Leaf B1", question = "Is B1 true?"),
list(name = "Leaf B2", question = "Is B2 true?")
)
)
)
)
# 2. Build the tree from the list
my_tree <- load_tree_node_list(my_data_list)
# 3. Print the resulting tree
print_tree(my_tree)
#> Tree Rule Answer Confidence
#> Root OR
#> |-- Leaf A
#> `-- Branch B AND
#> |-- Leaf B1
#> `-- Leaf B2