Compute nested list depth
Value
An integer scalar giving the maximum depth of x.
A non-list leaf has depth 0. A list containing only leaf values has depth
1. Deeper nested lists have larger depth according to the longest path to a
leaf.
See also
Other lstrrr_core:
list_delete(),
list_get(),
list_has(),
list_nleaf(),
list_path(),
list_set()
Examples
x <- list(
a = 1,
b = list(
x = 1,
y = list(i = 1, j = 2)
)
)
list_depth(x)
#> [1] 3
# A list with only leaf values has depth 1
list_depth(list(a = 1, b = 2))
#> [1] 1
# Non-list objects are leaves
list_depth(1) # 0
#> [1] 0
# Data frames are treated as leaves
list_depth(list(a = data.frame(x = 1:3)))
#> [1] 1
list_depth(x) # 1
#> [1] 3
