saveSQLite | R Documentation |
Save R data frame to SQLite file. This function saves a data frame to an SQLite database file. It can create indices on specified columns for faster querying. The database file is stored in the task's binary directory.
saveSQLite(
object,
task,
type,
subdir = NULL,
dirCreate = TRUE,
index = NULL,
tableName = "data",
overwrite = FALSE,
append = FALSE,
row.names = FALSE
)
object |
data.frame to serialize. |
task |
Object of class |
type |
Filename type. If the type is an array, the cocatenation of the elements is used with separator"-". Filenames have the form [task name]_[type].[ext] |
subdir |
(optional) Subdirectory. |
dirCreate |
Logical, if TRUE (by default) the directory is created. |
index |
character vector of column names to create indices on. |
tableName |
name of the table in the SQLite database. |
overwrite |
if |
append |
if |
row.names |
if |
The file name invisibly.
## Not run:
task <- loadTask("myproject","mypackage","mytask")
# create a sample data frame
df <- data.frame(a = 1:5, b = letters[1:5])
# save it to SQLite
fn <- saveSQLite(df, task, "testdb",tableName="table1",
index = c("a"))
# read it back
df_loaded <- readSQLite(task,"testdb",tableName="table1")
# print the loaded data frame
print(df_loaded)
# add second data frame
df2 <- data.frame(a = 6:10, b = letters[6:10])
saveSQLite(df2, task,"testdb",tableName="table2")
# query the data
query_result <- querySQLite("SELECT * FROM table2 WHERE a > 8",
task,"testdb")
print(query_result)
#' # append to the first table
saveSQLite(df2, task,"testdb",tableName="table1",append=TRUE)
# read the updated table
df_loaded <- readSQLite(task,"testdb",tableName="table1")
# print the updated data frame
print(df_loaded)
# cleanup
unlink(fn)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.