R/check-unique.R

Defines functions check_unique

Documented in check_unique

#' Check Unique
#'
#' Checks whether an object in unique (i.e. doesn't contain any duplicated elements).
#'
#'
#' @param x The object to check.
#' @param x_name A string of the name of the object.
#'
#' @return Throws an informative error or returns an invisible copy of
#' the object.
#' @export
check_unique <- function(x, x_name = substitute(x)) {
  if (!is.character(x_name)) x_name <- deparse(x_name)
  if (anyDuplicated(x)) error(x_name, " must be unique")
  invisible(x)
}
poissonconsulting/datacheckr documentation built on March 18, 2021, 10:37 a.m.