R/get_values.R

Defines functions get_values

Documented in get_values

#' Get values of column
#'
#' A function to determine what kind of values are present in columns.
#' @param df The dataframe
#' @param column Column to get values from.
#' @return The class of the column values
#' @examples
#' get_values(mtcars, "mpg")
#'
#' @export
get_values <- function(df, column) {
  if (inherits(df[[column]], "numeric")) {
    len <- length(unique(df[[column]]))
    ifelse(len > 15,
      return("Numeric values"),
      return(paste(unique(stats::na.omit(df[[column]])), sep = "", collapse = ", "))
    )
  } else if (inherits(df[[column]], "character")) {
    return(paste(range(df[[column]], na.rm = T), collapse = ", "))
  } else if (inherits(df[[column]], "logical")) {
    return("TRUE, FALSE")
  } else {
    return("NA")
  }
}

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.