df2sqlite: Write data frame to database

View source: R/df2sqlite.R

df2sqliteR Documentation

Write data frame to database

Description

Writes, replace of append a data frame to a database table. At the same time, setting the primary keys of the table.

Usage

df2sqlite(df, database, table, keys, replace = FALSE, append = FALSE)

Arguments

df

A data frame of values (or coercible to data.frame).

database

Database name, which will be converted to a database. If environment variable DATA_ARCHIVE has been set, then the database will be transformed to ⁠$DATA_ARCHIVE/<database>.sqlite⁠, otherwise, the database will be transformed to ⁠$HOME/Data/DBMS/<database>.sqlite.⁠

table

Table name in the database

keys

character vector, primary keys of data.frame df

append

logical value, whether append df to the table when it already exists. default: FALSE

reaplace

logical value, whether replace the table when it already exists. default: FALSE

Examples

## Not run: 
df <- mtcars
df$ID <- seq_along(nrows(df))
df2sqlite(df, database = "test", table = "mtcars", keys = "ID")

df$ID = df$ID + 100
try(df2sqlite(df, "test", "mtcars", "ID", append = TRUE))
df2sqlite(df, "test", "mtcars", "ID", append = TRUE)

df$ID = df$ID + 100
df2sqlite(df, "test", "mtcars", "ID", replace = TRUE)

## End(Not run)

liubianshi/lbs documentation built on Nov. 2, 2023, 11:06 a.m.