R/control_type_data.R

Defines functions control_type_data

Documented in control_type_data

#' @title Control all columns
#' 
#' @description This function controls the type of all columns of a dataframe, raising warnings and providing tips if type seems irrelevant.
#' 
#' @author Briac LE RAY (briac.leray@partnre.com)
#' 
#' @return Does not return anything. Only raises warnings in the console.
#' @param df The dataframe to control. Type = dataframe
#' @keywords control type data 
#' @examples control_type_data(df = my_dataframe)

control_type_data <- function(df) {
  for (col in names(df)) {
    type = typeof(df[[col]])
    
    if(!type %in% c("double")) { # Test if date
      if(detect_date(sample_n(df[col], 1000))) {
        print(paste0("AVERTISSEMENT TYPE DE DONNEE: La colonne ", col, " semble ĂȘtre enrichie de dates, or son type est ", type, ". Exemple de valeur: ", dplyr::first(na.omit(df[[col]]))))
        next
      }
    }
    
    if(!type %in% c("double", "integer")) { # Test if date
      if(detect_numeric(sample_n(df[col], 1000))) {
        print(paste0("AVERTISSEMENT TYPE DE DONNEE: La colonne ", col, " semble ĂȘtre enrichie de nombres, or son type est ", type, ". Exemple de valeur: ", dplyr::first(na.omit(df[[col]]))))
        next
      }
    }
  }
}
Tiipiac/StressTestOptimization documentation built on Dec. 18, 2021, 5:08 p.m.