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

View source: R/scrape.R

exportR Documentation

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

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

cpsievert/pitchRx documentation built on Aug. 19, 2023, 10:02 p.m.