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

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")
#> Source: lazy query [?? x 12] #> Database: sqlite 3.11.1 [:memory:] #> #> # S3: tbl_dbi #> mpg cyl disp hp drat wt qsec vs am gear carb #> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1 #> # ... with 1 more variables: model <chr>
# 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)
#> Joining, by = "cyl"
#> Source: lazy query [?? x 12] #> Database: sqlite 3.11.1 [:memory:] #> #> # S3: tbl_dbi #> mpg cyl disp hp drat wt qsec vs am gear carb #> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4 #> 2 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4 #> 3 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1 #> 4 18.7 8 360 175 3.15 3.440 17.02 0 0 3 2 #> 5 18.1 6 225 105 2.76 3.460 20.22 1 0 3 1 #> 6 14.3 8 360 245 3.21 3.570 15.84 0 0 3 4 #> # ... with more rows, and 1 more variables: model <chr>