Created
October 2, 2019 13:01
-
-
Save gshotwell/13f8c5268dd2269b6f7689c1ee2c7f0e to your computer and use it in GitHub Desktop.
Mock dplyr database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tbl.mock_db <- function(src, name, ...) { | |
return(src[[name]]) | |
} | |
new_mock_db <-function(path) { | |
files <- list.files(path, full.names = TRUE) | |
con <- purrr::map(files, ~readr::read_csv(., col_types = classes[[basename(.)]])) | |
names(con) <- gsub(".csv$", "", basename(files)) | |
class(con) <- c("mock_db", "list") | |
return(con) | |
} | |
con <- new_mock_db() | |
tbl(con, "table_1") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note that this will only work for functions which are translated between dplyr and your database.