Set an attribute on every inner node and leaf of a tree
Source:R/tree_traversal.R
set_node_attrs.RdTraverse through tree/list to set node attributes, e.g. change icons. Useful for directory structure icons where inner nodes are directories, leaves are files.
Examples
tree <- dfToTree(data.frame(Titanic), c("Sex", "Survived"))
str(set_node_attrs(tree, attr_name = "sttype", inner_val = "directory", leaf_val = "file"))
#> List of 2
#> $ Male :List of 2
#> ..$ No : chr ""
#> .. ..- attr(*, "sttype")= chr "file"
#> ..$ Yes: chr ""
#> .. ..- attr(*, "sttype")= chr "file"
#> ..- attr(*, "sttype")= chr "directory"
#> $ Female:List of 2
#> ..$ No : chr ""
#> .. ..- attr(*, "sttype")= chr "file"
#> ..$ Yes: chr ""
#> .. ..- attr(*, "sttype")= chr "file"
#> ..- attr(*, "sttype")= chr "directory"
#> - attr(*, "sttype")= chr "directory"