R/TableProfiler-R6.R

#' @title Generate a Table Profile
#'
#' @description Given \code{table}, when
#'   \code{TableProfiler$new(table)} is called, then a data.frame with that
#'   table attributes is formed and is accessible by calling
#'   \code{TableProfiler$new(table)$profile}.
#'
#' @return (`TableProfiler`) An object with the table profile.
#'
#' @export
#'
#' @examples
#' \dontrun{
#' mtcars_profiler <- TableProfiler$new(mtcars)
#' mtcars_profiler$profile
#' }
#'
TableProfiler <- R6::R6Class(
    classname = "TableProfiler",
    public = list(
        ## Public Methods
        initialize = function(table){
            .assert_is_non_empty_data.frame(table)

            private$.profile <-
                table[0,] %>%
                rbind(.find_col_types(table) %>% tibble::add_column(Attribute = "type", .before = 0))
        }
    ),
    private = list(
        ## Private Variables
        .profile = data.frame()
        ## Private Methods
    ),
    active = list(profile = function() return(private$.profile))
)# end R6
tidylab/tableware documentation built on July 6, 2019, 1:12 a.m.