Skip to content

Instantly share code, notes, and snippets.

@gshotwell
Created October 2, 2019 13:01
Show Gist options
  • Save gshotwell/13f8c5268dd2269b6f7689c1ee2c7f0e to your computer and use it in GitHub Desktop.
Save gshotwell/13f8c5268dd2269b6f7689c1ee2c7f0e to your computer and use it in GitHub Desktop.
Mock dplyr database
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")
@gshotwell
Copy link
Author

Note that this will only work for functions which are translated between dplyr and your database.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment