export: Export (append) a data.frame to a remote table in a database.

Description Usage Arguments Examples

Description

This function is convenient if you plan on repeatedly appending to a table in a database. All that is required is a database connection and a data.frame you want to export to that database. If you want to initiate a table with more columns use the template argument. Note that if the table already exists, the template argument will be ignored.

Usage

1
export(connect, value, name, template, ...)

Arguments

connect

database connection.

value

local data frame.

name

name of the remote table.

template

a named character vector. The names of the vector should contain the names of value. The values of this vector should contain the relevant field types.

...

arguments passed onto DBI::dbWriteTable

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
## Not run: 
library(dplyr)
my_db <- src_sqlite("DB.sqlite3")
data(pitches, package="pitchRx")
# Creates the 'pitches' table in the database
export(connect=my_db$con, value=pitches, name="pitches")
# Appends to the 'pitches' tables, but with the first column missing
export(connect=my_db$con, value=pitches[,-1], name="pitches")
tail(data.frame(collect(tbl(my_db, "pitches")))) #verify it appends correctly
# This data frame has a column that doesn't exist in the pitches table --
# so a new table is created.
export(connect=my_db$con, value=cbind(pitches, test="works"), name="pitches")

## End(Not run)

pitchRx documentation built on May 2, 2019, 5:56 a.m.

Related to export in pitchRx...