Learn R Programming

⚠️There's a newer version (2.4.6) of this package.Take me there.

RSQLite

RSQLite embeds the SQLite database engine in R, providing a DBI-compliant interface. SQLite is a public-domain, single-user, very light-weight database engine that implements a decent subset of the SQL 92 standard, including the core table creation, updating, insertion, and selection operations, plus transaction management.

You can install the latest released version from CRAN with:

install.packages("RSQLite")

Or install the latest development version from github with:

# install.packages("devtools")
devtools::install_github("rstats-db/RSQLite")

To install from github, you'll need a development environment.

Basic usage

library(DBI)
# Create an ephemeral in-memory RSQLite database
con <- dbConnect(RSQLite::SQLite(), ":memory:")

dbListTables(con)
dbWriteTable(con, "mtcars", mtcars)
dbListTables(con)

dbListFields(con, "mtcars")
dbReadTable(con, "mtcars")

# You can fetch all results:
res <- dbSendQuery(con, "SELECT * FROM mtcars WHERE cyl = 4")
dbFetch(res)
dbClearResult(res)

# Or a chunk at a time
res <- dbSendQuery(con, "SELECT * FROM mtcars WHERE cyl = 4")
while(!dbHasCompleted(res)){
  chunk <- dbFetch(res, n = 5)
  print(nrow(chunk))
}
# Clear the result
dbClearResult(res)

# Disconnect from the database
dbDisconnect(con)

Acknowledgements

Many thanks to Doug Bates, Seth Falcon, Detlef Groth, Ronggui Huang, Kurt Hornik, Uwe Ligges, Charles Loboz, Duncan Murdoch, and Brian D. Ripley for comments, suggestions, bug reports, and/or patches.

Update version of SQLite

  1. Download latest SQLite source

    latest <- "http://sqlite.org/2014/sqlite-amalgamation-3080600.zip"
    tmp <- tempfile()
    download.file(latest, tmp)
    unzip(tmp, exdir = "src/sqlite", junkpaths = TRUE)
    unlink("src/sqlite/shell.c")
  2. Update DESCRIPTION for included version of SQLite

  3. Update NEWS

Update datasets database

RSQLite includes one SQLite database (accessible from datasetsDb() that contains all data frames in the datasets package. This is the code that created it.

tables <- unique(data(package = "datasets")$results[, 3])
tables <- tables[!grepl("(", tables, fixed = TRUE)]

con <- dbConnect(SQLite(), "inst/db/datasets.sqlite")
for(table in tables) {
  df <- getExportedValue("datasets", table)
  if (!is.data.frame(df)) next
  
  message("Creating table: ", table)
  dbWriteTable(con, table, as.data.frame(df), overwrite = TRUE)
}

Copy Link

Version

Install

install.packages('RSQLite')

Monthly Downloads

178,166

Version

1.0.0

License

LGPL (>= 2)

Issues

Pull Requests

Stars

Forks

Maintainer

Hadley Wickham

Last Published

February 6th, 2026

Functions in RSQLite (1.0.0)

initExtension

Add useful extension functions.
sqliteQuickColumn

Return an entire column from a SQLite database
datasetsDb

A sample sqlite database.
SQLiteResult-class

Class SQLiteResult
dbDataType,SQLiteConnection-method

Determine the SQL Data Type of an R object.
sqliteCopyDatabase

Copy a SQLite database
SQLiteDriver-class

Class SQLiteDriver with constructor SQLite.
SQLiteConnection-class

Class SQLiteConnection.
dbRemoveTable,SQLiteConnection,character-method

Remove a table from the database.
dbSendPreparedQuery

Generics for getting and sending prepared queries.
query

Execute a SQL statement on a database connection
dbListTables,SQLiteConnection-method

List available SQLite tables.
dbListFields,SQLiteConnection,character-method

List fields in specified table.
transactions

SQLite transaction management.
dbReadTable,SQLiteConnection,character-method

Convenience functions for importing/exporting DBMS tables
dbExistsTable,SQLiteConnection,character-method

Does the table exist?
sqlite-meta

Database interface meta-data.
dbWriteTable,SQLiteConnection,character,data.frame-method

Write a local data frame or file to the database.
summary

Summary methods
dbIsValid

Check whether an SQLite object is valid or not.
sqliteBuildTableDefinition

Build the SQL CREATE TABLE definition as a string
make.db.names,SQLiteConnection,character-method

Make R/S-Plus identifiers into legal SQL identifiers
dbBeginTransaction

Generic for creating a new transaction.
dbGetInfo

Get metadata about a database object.
dbGetException,SQLiteConnection-method

Get the last exception from the connection.
dbUnloadDriver,SQLiteDriver-method

Unload SQLite driver.
dbConnect,SQLiteDriver-method

Connect to/disconnect from a SQLite database.