depth | R Documentation |
Recursively determine depth of a list
depth(lst, d = 0L) depth_while(lst, d = 0L)
lst |
input list to determine depth of |
d |
optional default starting or return value if this is not a list; defaults to |
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.
An integer of length 1
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
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))))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.