R/utils.R

# Aggregate certain object types into a count
.count_items <- function (x, na.rm = TRUE) {
  if (is.data.frame(x)) vctrs::vec_size(x) # data frame
  else if (!all(is.numeric(x))) {
    vctrs::vec_size(if (na.rm) stats::na.omit(x) else x) # Non-numeric
  } else if (vctrs::vec_is_empty(x)) 0 # empty numeric
  else x # Usable numeric
}

Try the utile.tools package in your browser

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

utile.tools documentation built on Feb. 16, 2023, 10:08 p.m.