R/list_depth.R

Defines functions list_depth

Documented in list_depth

#' Function to find the level of list nesting
#'
#' @param List an object of class 'list'.
#'
#' @return an integer; level of list nesting
#'
#' @author Kasia Sawicka
#' 
#' @examples
#' 
#' a <- list(1,2)
#' list_depth(a)
#' 
#' a <- list(list(1, 2), 3)
#' list_depth(a)
#' 
#' @export
list_depth <- function(List) {
  ifelse(is.list(List), 1L + max(sapply(List, list_depth)), 0L)
}

Try the spup package in your browser

Any scripts or data that you put into this service are public.

spup documentation built on May 1, 2020, 1:07 a.m.