R/list_breaker.R

Defines functions list_breaker

Documented in list_breaker

#' Breaks out lists of lists by sub-list length
#'
#' XXXXXX
#'
#' @importFrom purrr map
#'
#' @param x a list of lists, with at least some sub-lists having length
#'   \code{len}
#' @param len an numeric value for the length of sub-lists that
#'   \code{list_breaker} should break out.  Must be a whole number.
#' @return returns a list of lists, with all sub-lists having length \code{len}

list_breaker <- function(x, len){

  if(is.list(x) == FALSE){
    stop("x must be a list")
  }

  if(all.equal(len, as.integer(len)) == FALSE){
    stop("len must be a whole number")
  }

  list_portion <- x[purrr::map(x, length) == len]

  return(list_portion)

}

Try the SwimmeR package in your browser

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

SwimmeR documentation built on March 31, 2023, 8:27 p.m.