Counts the number of leaf nodes in a tree. This equals the length of the
flat list produced by flatten() on the original structure.
Arguments
- x
(
Node)
A tree node as returned bybuild_tree().
Examples
tree <- build_tree(list(a = 1, b = list(c = 2, d = 3)))
tree_size(tree)
#> [1] 3
tree_size(build_tree(list(1)))
#> [1] 1