Skip to contents

Counts the number of leaf nodes in a tree. This equals the length of the flat list produced by flatten() on the original structure.

Usage

tree_size(x)

Arguments

x

(Node)
A tree node as returned by build_tree().

Value

A scalar integer.

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