R/empty.R

Defines functions list_drop_empty

Documented in list_drop_empty

#' Drop empty elements from a list
#'
#' `list_drop_empty()` removes empty elements from a list. This includes `NULL`
#' elements along with empty vectors, like `integer(0)`. This is equivalent to,
#' but faster than, `vec_slice(x, list_sizes(x) != 0L)`.
#'
#' @section Dependencies:
#' - [vec_slice()]
#'
#' @param x A list.
#'
#' @export
#' @examples
#' x <- list(1, NULL, integer(), 2)
#' list_drop_empty(x)
list_drop_empty <- function(x) {
  .Call(vctrs_list_drop_empty, x)
}

Try the vctrs package in your browser

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

vctrs documentation built on Oct. 13, 2023, 1:05 a.m.