# find_col_types ---------------------------------------------------------------
#
#' @title Find the Class of each Variable in a data.frame
#'
#' @param .data (`data.frame`) The table to profile.
#'
#' @return (`data.frame`) A table with one row containing the column types and
#' p columns representing the table column names.
#'
#' @export
#' @keywords internal
#'
#' @note Date and Time variables return tibble-style notations rather than their
#' class:
#' * A date, e.g. "2019-06-16" returns "date" rather than "Date"
#' * A time within a day, e.g. "12:57:50" returns "time" rather than "POSIXct"
#' * A date-time, e.g. "2019-06-16 12:57:50" returns "dttm" rather than POSIXct"
#'
#' @seealso \link[base]{class}
#' @family TableProfiler methods
#'
#' @examples
#' \dontrun{
#' .find_col_types(mtcars)
#' }
#'
.find_col_types <- function(.data){
## Helper Functios
.relabel_Date_as_date <- function(x) ifelse(x %in% "Date", "date", x)
.relabel_POSIXct_as_dttm <- function(x) ifelse(x %in% c("POSIXct", "POSIXt"), "dttm", x)
.relabel_Period_as_time <- function(x) ifelse(x %in% "Period", "time", x)
.class <- function(x) class(x)[1]
## Programming Logic
col_types <-
sapply(.data, .class) %>%
.relabel_Date_as_date() %>%
.relabel_POSIXct_as_dttm() %>%
.relabel_Period_as_time() %>%
as.character() %>% t() %>%
as.data.frame(stringsAsFactors = FALSE) %>%
stats::setNames(names(.data))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.