write.dbi.ffdf {ETLUtils} | R Documentation |
Write ffdf data to a database table by using a DBI connection.
Description
Write ffdf
data to a database table by using a DBI connection.
This can for example be used to store large ffdf datasets from R in
Oracle, SQLite, MySQL, PostgreSQL, Hive or other SQL databases.
Mark that for very large datasets, these SQL databases might have tools to speed up by bulk loading.
You might also consider that as an alternative to using this procedure.
Usage
write.dbi.ffdf(
x,
name,
dbConnect.args = list(drv = NULL, dbname = NULL, username = "", password = ""),
RECORDBYTES = sum(.rambytes[vmode(x)]),
BATCHBYTES = getOption("ffbatchbytes"),
by = NULL,
VERBOSE = FALSE,
...
)
Arguments
x |
the |
name |
character string with the name of the table to store the data in. Passed on to |
dbConnect.args |
a list of arguments to pass to DBI's |
RECORDBYTES |
optional integer scalar representing the bytes needed to process a single row of the ffdf |
BATCHBYTES |
integer: bytes allowed for the size of the data.frame storing the result of reading one chunk.
See documentation in |
by |
integer passed on to |
VERBOSE |
logical: TRUE to verbose timings for each processed chunk (default FALSE). |
... |
optional parameters passed on to |
Details
Opens up the DBI connection using DBI::dbConnect
, writes data to the SQL table
using DBI::dbWriteTable
by extracting the data in batches from the ffdf
and appending them to the table.
Value
invisible()
See Also
Examples
require(ff)
##
## Example query using data in sqlite
##
require(RSQLite)
dbfile <- system.file("smalldb.sqlite3", package="ETLUtils")
drv <- dbDriver("SQLite")
query <- "select * from testdata limit 10000"
x <- read.dbi.ffdf(query = query, dbConnect.args = list(drv = drv, dbname = dbfile),
first.rows = 100, next.rows = 1000, VERBOSE=TRUE)
## copy db in package folder to temp folder as CRAN does not allow writing in package dirs
dbfile <- tempfile(fileext = ".sqlite3")
file.copy(from = system.file("smalldb.sqlite3", package="ETLUtils"), to = dbfile)
Sys.chmod(dbfile, mode = "777")
write.dbi.ffdf(x = x, name = "helloworld", row.names = FALSE, overwrite = TRUE,
dbConnect.args = list(drv = drv, dbname = dbfile),
by = 1000, VERBOSE=TRUE)
test <- read.dbi.ffdf(query = "select * from helloworld",
dbConnect.args = list(drv = drv, dbname = dbfile))
## clean up for CRAN
file.remove(dbfile)
## Not run:
require(ROracle)
write.dbi.ffdf(x = x, name = "hellooracle", row.names = FALSE, overwrite = TRUE,
dbConnect.args = list(drv = dbDriver("Oracle"),
user = "YourUser", password = "YourPassword", dbname = "Mydatabase"),
VERBOSE=TRUE)
## End(Not run)