R/unique_values.R

Defines functions unique_values

Documented in unique_values

#' Unique value check
#'
#' Checks if there are non-unique values in dataset.
#' @param value Column from which an unique vector will be formed.
#' @param df Dataframe in which lies the column to be checked.
#' @param value_col Name of the column to be checked, in string format.
#' @param value_name Name of the variable tested.
#' @return No R object return, performs only a check.
#' @export
unique_values <- function(value, df, value_col, value_name){
  if(nrow(as.data.frame(unique(value)))<nrow(df)){
    duplicates = df %>% group_by(UQ(sym(value_col))) %>% summarise(n=n()) %>% filter(.data$n>1)
    colnames(duplicates) <- c("value", "n")
    stop(paste("Check the data! There are duplicates!", duplicates$value))
  } else{
    message(paste('Only unique values:', value_name))
  }
}

Try the DIETCOST package in your browser

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

DIETCOST documentation built on June 8, 2025, 1:51 p.m.