Learn R Programming

pitchRx (version 1.8.2)

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

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

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

Run this code
## 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)

Run the code above in your browser using DataLab