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)
}
ksawicka/spup documentation built on Jan. 14, 2024, 11:28 p.m.