Skip to contents

Constructs a tree from a data frame that is already in memory, where the hierarchy is defined using a path string for each node (e.g., "Root/Branch/Leaf").

Usage

load_tree_df_path(df, delim = "/")

Arguments

df

A data frame with a column named path containing the node paths, and other optional attribute columns like question and rule.

delim

The character used to separate nodes in the path string. Defaults to "/".

Value

A data.tree object.

Details

This is a core constructor function, typically called by a wrapper like load_tree_csv_path(), which handles reading the data from a file. The node's name is inferred from the last element of its path.

See also

load_tree_csv_path() to read this format from a file.

Examples


# Create a sample data frame in path format
path_df <- data.frame(
  path = c("Root", "Root/Branch1", "Root/Branch1/LeafA", "Root/Branch2"),
  rule = c("AND", "OR", NA, NA),
  question = c(NA, "Is Branch1 relevant?", "Is LeafA true?", "Is Branch2 true?")
)

# Build the tree
my_tree <- load_tree_df_path(path_df)
print(my_tree)
#>       levelName
#> 1 Root         
#> 2  ¦--Branch1  
#> 3  ¦   °--LeafA
#> 4  °--Branch2