R/r6-HousePricesData.R

#' @title Establish Connection to House Prices Data Sets 
#' @export
HousePricesData <- R6::R6Class(
    "HousePricesData",
    public = list(
        #' @description
        #' Initiate object
        initialize = function() {
            if(is.null(self$con)){
                self$con
                copy_to <- purrr::partial(dplyr::copy_to, overwrite = TRUE)
                
                temp_env <- new.env()
                load(file = usethis::proj_path("data", "train_set", ext = "rda"), envir = temp_env)
                load(file = usethis::proj_path("data", "test_set", ext = "rda"), envir = temp_env)
                load(file = usethis::proj_path("data", "code_book", ext = "rda"), envir = temp_env)
                
                self$con <- DBI::dbConnect(RSQLite::SQLite(), ":memory:")
                copy_to(self$con, temp_env$train_set, "train_set")
                copy_to(self$con, temp_env$test_set, "test_set")
                copy_to(self$con, temp_env$code_book, "code_book")
                rm(temp_env)
            }
            
            invisible(self)
        },
        #' @field con Database Connection
        con = NULL
    ) # Public
)# HousePricesData
Kiwi-Random-House/R-Projects documentation built on Dec. 31, 2020, 2:10 p.m.