Using SQLite in R

This uses the RSQLite and DBI packages.

Contents

[edit] 1 Connect to a database

driver <- SQLite(max.con=16);
dbconnection <- dbConnect(driver, dbname="FILENAME");

[edit] 2 Get information on the database and tables

List the tables in a connected database:

dbListTables(dbconnection)

[edit] 3 Run a search

A quick function to get a table out of a query:

fetchResults <- function(connection, query) {
# Run the query
  results <- dbSendQuery(connection, query);
# Fetch all results into a data.frame
  table <- fetch(results, n = -1);
# Clear the results
  dbClearResult(results);
  return(table);
}

[edit] 4 Disconnect

dbDisconnect(dbconnection)
XHTML 1.1 CSS 2 Sec 508