copy_to.src_sql {dbplyr} | R Documentation |
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.
## S3 method for class 'src_sql' copy_to(dest, df, name = deparse(substitute(df)), overwrite = FALSE, types = NULL, temporary = TRUE, unique_indexes = NULL, indexes = NULL, analyze = TRUE, ...)
dest |
remote data source |
df |
A local data frame, a |
name |
name for new remote table. |
overwrite |
If |
types |
a character vector giving variable types to use for the columns. See http://www.sqlite.org/datatype3.html for available types. |
temporary |
if |
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 |
... |
other parameters passed to methods. |
A tbl()
object (invisibly).
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") cyl8 <- mtcars2 %>% filter(cyl == 8) cyl8_cached <- copy_to(src_memdb(), cyl8) # 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)