depth: depth

View source: R/depth.R

depthR Documentation

depth

Description

Recursively determine depth of a list

Usage

depth(lst, d = 0L)

depth_while(lst, d = 0L)

Arguments

lst

input list to determine depth of

d

optional default starting or return value if this is not a list; defaults to 0L

Details

There are two versions of this function. depth is a recursive version, and depth_while is an imperitive version. Both achieve the same end results, although one might be more performant that the other, depending on the usage scenario.

In practice, it is unlikely performance will ever be an issue with this function, as meaningful differences between the two approaches will only be apparent with tens of thousands of runs, and checking list depth is almost always a one-off, usually as a part of function input validation.

Value

An integer of length 1

Note

This is mainly used as a helper function to check inputs, but generally useful enough to include as a standalone

Credit to: http://stackoverflow.com/a/13433689/1270695 for depth

Examples

depth(list(1:3))
depth(list(list(1:3)))
depth(list(1:3, "a", list(1:2)))
depth(list(1:3, "a", list(list(1:2))))

slin30/wzMisc documentation built on Jan. 27, 2023, 1 a.m.