R/get_cc_data_as_tmp_file.R

Defines functions get_cc_data_as_tmp_file

Documented in get_cc_data_as_tmp_file

#' Get Data from MASTER Credit Card tracking sheet
#' @import mirCat
#' @import readr
#' @import dplyr
#' @importFrom magrittr %>%
#' @import googlesheets
#' @importFrom somersaulteR call_mr_clean
#' @export

get_cc_data_as_tmp_file <-
        function() {
                #x <- mirCat::gs_read_tmp_csv("MASTER Credit Card")
                # tmp_fn <- tempfile(tmpdir = tempdir(),
                #                     fileext = ".xlsx")

                tabnames <- mirCat::gs_tab_names("MASTER Credit Card", system.sleep = 3)

                gs_ss <- mirCat::gs_ss_by_name("MASTER Credit Card")
                x <- list()
                for (i in 1:length(tabnames)) {
                        tmp_fn <- tempfile(tmpdir = tempdir(),
                                            fileext = ".csv")
                        googlesheets::gs_download(from = gs_ss,
                                                  ws = tabnames[i],
                                                  to = tmp_fn)
                        x[[i]] <- readr::read_csv(tmp_fn, col_types = readr::cols(.default = "c"))
                        names(x)[i] <- tabnames[i]
                        unlink(tmp_fn)
                }


                # googlesheets::gs_download(from = gsheet_metadata,
                #                           to = tmp_fn,
                #                           overwrite = TRUE)
                # tabnames <- c("APR", "LIMIT", "SPEND", "ANNUAL_FEE")
                #
                # x <- list()
                # for (i in 1:length(tabnames)) {
                #         x[[i]] <- readxl::read_xlsx(tmp_fn,
                #                                     sheet = tabnames[i]) %>%
                #                 somersaulteR::call_mr_clean()
                # }
                # names(x) <- tabnames
                return(x)
                # unlink(tmp_fn)
        }
meerawhy/financeTracker documentation built on Dec. 3, 2019, 9:56 p.m.