R/check_x.R

Defines functions check_x

Documented in check_x

#' @title Check input
#'
#' @description Checks if x is a proper input
#'
#' @param x Vector of dimension S (number of species) with the number of individuals observed in each species, or the distribution frequencies of species. NA values are allowed.
#'
#' @return x without NA or 0 values
#'
#' @keywords internal
check_x  <- function(x){
  x <- stats::na.omit(x)
  stopifnot(is.numeric(x))
  x <- ifelse(x==0, NA, x)
  x <- stats::na.omit(x)
  stopifnot(all(x >0))
  if (sum(x) !=1)  stopifnot(isTRUE(all.equal(x, round(x))))
  return(x)
}

Try the diversityArch package in your browser

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

diversityArch documentation built on June 13, 2026, 5:07 p.m.