hier_info() computes various information about hierarchy codes or the (nested) hierarchy.

hier_info(tree, nodes = NULL)

Arguments

tree

a (nested) hierarchy created using hier_create() or modified using hier_add(), hier_delete() or hier_rename().

nodes

(character) names of new nodes that should be added below "root"

Value

a list with information about the required nodes. If nodes is NULL (the default), the information is computed for all available nodes of the hierarchy. The following properties are computed:

  • exists: (logical) does the node exist

  • name: (character) node name

  • is_rootnode: (logical) is the node the overall root of the tree?

  • level: (numeric) what is the level of the node

  • is_leaf: (logical) is the node a leaf?

  • siblings: (character) what are siblings of this node?

  • contributing_codes: (character) which codes are contributing to this node? If none (it is a leaf), NA is returned

  • children: (character) the names of the children of the node. If it has none (it is a leaf), NA is returned

  • is_bogus: (logical) is it a bogus code (i. e the only children of a leaf?)

Examples

h <- hier_create(root = "Total",  nodes = LETTERS[1:3])
h <- hier_add(h, root = "A", nodes = c("a1", "a5"))
hier_display(h)
#> Total
#> ├─A
#> │ ├─a1
#> │ └─a5
#> ├─B
#> └─C

# about a specific node
hier_info(h, nodes = "a1")
#> $name
#> [1] "a1"
#> 
#> $is_rootnode
#> [1] FALSE
#> 
#> $level
#> [1] 3
#> 
#> $is_leaf
#> [1] TRUE
#> 
#> $siblings
#> [1] "a5"
#> 
#> $contributing_codes
#> [1] "a1"
#> 
#> $children
#> character(0)
#> 
#> $parent
#> [1] "A"
#> 
#> $is_bogus
#> [1] FALSE
#> 
#> $parent_bogus
#> character(0)
#> 

# about all nodes
hier_info(h)
#> $Total
#> $Total$name
#> [1] "Total"
#> 
#> $Total$is_rootnode
#> [1] TRUE
#> 
#> $Total$level
#> [1] 1
#> 
#> $Total$is_leaf
#> [1] FALSE
#> 
#> $Total$siblings
#> character(0)
#> 
#> $Total$contributing_codes
#> [1] "B"  "C"  "a1" "a5"
#> 
#> $Total$children
#> [1] "A" "B" "C"
#> 
#> $Total$parent
#> [1] "Total"
#> 
#> $Total$is_bogus
#> [1] FALSE
#> 
#> $Total$parent_bogus
#> character(0)
#> 
#> 
#> $A
#> $A$name
#> [1] "A"
#> 
#> $A$is_rootnode
#> [1] FALSE
#> 
#> $A$level
#> [1] 2
#> 
#> $A$is_leaf
#> [1] FALSE
#> 
#> $A$siblings
#> [1] "B" "C"
#> 
#> $A$contributing_codes
#> [1] "a1" "a5"
#> 
#> $A$children
#> [1] "a1" "a5"
#> 
#> $A$parent
#> [1] "Total"
#> 
#> $A$is_bogus
#> [1] FALSE
#> 
#> $A$parent_bogus
#> character(0)
#> 
#> 
#> $a1
#> $a1$name
#> [1] "a1"
#> 
#> $a1$is_rootnode
#> [1] FALSE
#> 
#> $a1$level
#> [1] 3
#> 
#> $a1$is_leaf
#> [1] TRUE
#> 
#> $a1$siblings
#> [1] "a5"
#> 
#> $a1$contributing_codes
#> [1] "a1"
#> 
#> $a1$children
#> character(0)
#> 
#> $a1$parent
#> [1] "A"
#> 
#> $a1$is_bogus
#> [1] FALSE
#> 
#> $a1$parent_bogus
#> character(0)
#> 
#> 
#> $a5
#> $a5$name
#> [1] "a5"
#> 
#> $a5$is_rootnode
#> [1] FALSE
#> 
#> $a5$level
#> [1] 3
#> 
#> $a5$is_leaf
#> [1] TRUE
#> 
#> $a5$siblings
#> [1] "a1"
#> 
#> $a5$contributing_codes
#> [1] "a5"
#> 
#> $a5$children
#> character(0)
#> 
#> $a5$parent
#> [1] "A"
#> 
#> $a5$is_bogus
#> [1] FALSE
#> 
#> $a5$parent_bogus
#> character(0)
#> 
#> 
#> $B
#> $B$name
#> [1] "B"
#> 
#> $B$is_rootnode
#> [1] FALSE
#> 
#> $B$level
#> [1] 2
#> 
#> $B$is_leaf
#> [1] TRUE
#> 
#> $B$siblings
#> [1] "A" "C"
#> 
#> $B$contributing_codes
#> [1] "B"
#> 
#> $B$children
#> character(0)
#> 
#> $B$parent
#> [1] "Total"
#> 
#> $B$is_bogus
#> [1] FALSE
#> 
#> $B$parent_bogus
#> character(0)
#> 
#> 
#> $C
#> $C$name
#> [1] "C"
#> 
#> $C$is_rootnode
#> [1] FALSE
#> 
#> $C$level
#> [1] 2
#> 
#> $C$is_leaf
#> [1] TRUE
#> 
#> $C$siblings
#> [1] "A" "B"
#> 
#> $C$contributing_codes
#> [1] "C"
#> 
#> $C$children
#> character(0)
#> 
#> $C$parent
#> [1] "Total"
#> 
#> $C$is_bogus
#> [1] FALSE
#> 
#> $C$parent_bogus
#> character(0)
#> 
#>