SQL databases are the cornerstone of many data science efforts. We provide this simple function to export all the available datasets in available_datasets() to any relational database supported by dbplyr.

datasets_to_sql(
  con,
  dataset_accessors = available_datasets()$accessor,
  overwrite = TRUE,
  ...
)

Arguments

con

a remote data source. See dplyr::copy_to()

dataset_accessors

character() vector of accessors for datasets. The accessor column of available_datasets() is the default, meaning that all data.frame-like datasets will be written to the SQL destination.

overwrite

If TRUE, will overwrite an existing table with name name. If FALSE, will throw an error if name already exists.

...

passed on to dplyr::copy_to()

Value

used for side effects

Details

Create connections using RSQLite::SQLite() for RSQLite, RMariaDB::MariaDB() for RMariaDB, RPostgres::Postgres() for RPostgres, odbc::odbc() for odbc, and bigrquery::bigquery() for BigQuery.

See also

Author

Sean Davis seandavi@gmail.com

Examples

if(requireNamespace("RSQLite", quietly=TRUE) 
   & requireNamespace("DBI", quietly=TRUE)) {
  sql = DBI::dbConnect(RSQLite::SQLite(), ':memory:')
  datasets_to_sql(sql, dataset_accessors = "coronadatascraper_data")
  DBI::dbListTables(sql)
  DBI::dbDisconnect(sql)
} else {
  print("install.packages('RSQLite') to run this example")
}
#> coronadatascraper_data
#> writing