dbplyr (version 0.0.0.9000)

copy_to.src_sql: Copy a local data frame to a DBI backend.

Description

This copy_to() method works for all DBI sources. It is useful for copying small amounts of data to a database for examples, experiments, and joins. By default, it creates temporary tables which are typically only visible to the current connection to the database.

Usage

# S3 method for src_sql
copy_to(dest, df, name = deparse(substitute(df)),
  overwrite = FALSE, types = NULL, temporary = TRUE,
  unique_indexes = NULL, indexes = NULL, analyze = TRUE, ...)

Arguments

dest
remote data source
df
local data frame
name
name for new remote table.
overwrite
If TRUE, will overwrite an existing table with name name. If FALSE, will throw an error if name already exists.
types
a character vector giving variable types to use for the columns. See http://www.sqlite.org/datatype3.html for available types.
temporary
if TRUE, will create a temporary table that is local to this connection and will be automatically deleted when the connection expires
unique_indexes
a list of character vectors. Each element of the list will create a new unique index over the specified column(s). Duplicate rows will result in failure.
indexes
a list of character vectors. Each element of the list will create a new index.
analyze
if TRUE (the default), will automatically ANALYZE the new table so that the query optimiser has useful information.
...
other parameters passed to methods.

Value

A tbl() object (invisibly).

Examples

Run this code
library(dplyr)
set.seed(1014)

mtcars$model <- rownames(mtcars)
mtcars2 <- src_memdb() %>%
  copy_to(mtcars, indexes = list("model"), overwrite = TRUE)
mtcars2 %>% filter(model == "Hornet 4 Drive")

# copy_to is called automatically if you set copy = TRUE
# in the join functions
df <- tibble(cyl = c(6, 8))
mtcars2 %>% semi_join(df, copy = TRUE)

Run the code above in your browser using DataLab