R/column_type_checker.R

Defines functions column_type_checker

Documented in column_type_checker

#' Quick function for checking if a column is of the right type using data-masking
#'
#' @param data Data Frame or Tibble object
#' @param column Column you want to check
#' @param type `column`'s expected type
#'
#' @return a character vector
#' @export
#'
#' @examples
#' \dontrun{
#' check_text <- df %>% column_type_checker(text_var, "character")
#'
#' if(check_text == "no") stop("Wrong type")
#'
#' }
column_type_checker <- function(data,
                                column,
                                type){
  if(!all(class(data %>% dplyr::pull({{column}})) == type)){
    return("no")
  } else {
    return("yes")
  }

}
jpcompartir/JPackage documentation built on March 20, 2023, 4 a.m.