Learn R Programming

dm (version 0.0.6.9000)

dm_copy_to: Copy a dm-object to a different data source

Description

dm_copy_to() takes a dplyr::src_dbi object or a DBI::DBIConnection object as its first argument and a dm object as its second argument. The latter is copied to the former. By default, temporary tables will be created and the key constraints will be set (currently only on MSSQL and Postgres databases).

Usage

dm_copy_to(
  dest,
  dm,
  ...,
  types = NULL,
  overwrite = NULL,
  indexes = NULL,
  unique_indexes = NULL,
  set_key_constraints = TRUE,
  unique_table_names = FALSE,
  table_names = NULL,
  temporary = TRUE
)

Arguments

dest

An object of class "src" or "DBIConnection".

dm

A dm object.

...

Possible further arguments passed to dplyr::copy_to(), which is used on each table.

overwrite, types, indexes, unique_indexes

Must remain NULL.

set_key_constraints

Boolean variable, if TRUE will mirror dm key constraints on a database.

unique_table_names

Boolean, if FALSE (default), the original table names will be used, if TRUE, unique table names will be created based on the original table names.

table_names

A named character vector, containing the names that you want the tables in the dm to have after copying them to the database. The table names within the dm will remain unchanged. The name of each element of the vector needs to be one of the table names of the dm. Those tables of the dm that are not addressed will be called by their original name on the database.

temporary

Boolean variable, if TRUE, only temporary tables will be created. These tables will vanish when disconnecting from the database.

Value

A dm object on the given src.

Details

No tables will be overwritten; passing overwrite = TRUE to the function will give an error. Types are determined separately for each table, setting the types argument will also throw an error. The arguments are included in the signature to avoid passing them via the ... ellipsis.

See Also

Other DB interaction functions: dm_learn_from_db()

Examples

Run this code
# NOT RUN {
src_sqlite <- dplyr::src_sqlite(":memory:", create = TRUE)
iris_dm <- dm_copy_to(
  src_sqlite,
  as_dm(list(iris = iris)),
  set_key_constraints = FALSE
)
# }

Run the code above in your browser using DataLab