datasets_to_sql: Build a data warehouse of all datasets in one line

View source: R/datasets_to_sqlite.R

datasets_to_sqlR Documentation

Build a data warehouse of all datasets in one line

Description

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.

Usage

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()

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.

Value

used for side effects

Author(s)

Sean Davis seandavi@gmail.com

See Also

dplyr::copy_to()

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")
}


seandavi/sars2pack documentation built on May 13, 2022, 3:41 p.m.