Traverse through tree/list to set node attributes, e.g. change icons. Useful for directory structure icons where inner nodes are directories, leafs are files.

set_node_attrs(tree, attr_name, inner_val, leaf_val)

Arguments

tree

named nested list

attr_name

name of attribute to set

inner_val

value of attribute for inner tree nodes

leaf_val

value of attribute for outer tree nodes

Value

named nested list

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"