listless (version 0.0-2)

list_depth: Get the depth of a list

Description

Gets the depth of a list (at its deepest point).

Usage

list_depth(l, prune_empty_elts = FALSE)

Arguments

l
A variable, probably a list.
prune_empty_elts
A logical value. Should empty elements be pruned without counting them?

Value

A non-negative integer of the deepest depth of the list.

See Also

This is loosely based upon list.depth (internal to older versions of the Zelig package), but gives different answers.

Examples

Run this code
list_depth(list(1))
list_depth(list(1, list(2:3, 4:6)))

# Atomic variables have depth 0
list_depth(1)

# Empty elements can be pruned before counting
list_depth(list())
list_depth(list(), prune_empty_elts = TRUE)

Run the code above in your browser using DataCamp Workspace