Skip to content

Instantly share code, notes, and snippets.

@alienfluid
Created January 31, 2014 22:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alienfluid/8744869 to your computer and use it in GitHub Desktop.
Save alienfluid/8744869 to your computer and use it in GitHub Desktop.
Find the maximum depth of a nested list structure
a = list(list("a", "b"), list(list(list(list(list("c")))), list(list("d"))), 1)
is_list = function (x) {
if (class(x) == "list") {
1 + max(sapply(x, is_list))
} else {
0
}
}
max(sapply(a, is_list))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment