R/test_all_equal.R

Defines functions test_all_equal

Documented in test_all_equal

#' Test all equal
#'
#' Test whether all values in a vector are equal.
#' @param x Vector to test.
#' @param na.rm default: FALSE. exclude NAs from the test.
#' @return Boolean result of the test
#' @examples
#' test_all_equal(c(5, 5, 5))
#'
#' test_all_equal(c(5, 6, 3))
#'
#' @family tests
#' @export
test_all_equal <- function(x, na.rm = FALSE) {
  if (!na.rm) {
    return(length(unique(x)) <= 1)
  } else {
    return(length(unique(x[!is.na(x)])) <= 1)
  }
}

Try the vvauditor package in your browser

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

vvauditor documentation built on May 29, 2024, 12:20 p.m.