Using SQLite in R

[This article was first published on Digital Hardcore » rbloggers, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Working on big data requires a clean and robust approach on storing and accessing the data. SQLite is an all inclusive server-less database system in a single file. This is very convenient for data exchange between colleagues. Here is a workflow of SQLite data accessing and data storing in R.

Connect to an SQLite database file and get a table directly to a data.frame data-type. Useful when handling big chunks of data or when analyzing subsets of data which can be retrieved via an SQLite query.

library("RSQLite")# connect to the sqlite filecon = dbConnect(drv="SQLite", dbname="country.sqlite")# get a list of all tablesalltables = dbListTables(con)# get the populationtable as a data.framep1 = dbGetQuery( con,'select * from populationtable' )# count the areas in the SQLite tablep2 = dbGetQuery( con,'select count(*) from areastable' )# find entries of the DB from the last weekp3 = dbGetQuery(con, "SELECT population WHERE DATE(timeStamp) < DATE('now', 'weekday 0', '-7 days')")#Clear the results of the last querydbClearResult(p3)#Select population with managerial type of jobp4 = dbGetQuery(con, "select * from populationtable where jobdescription like '%manager%'")

To leave a comment for the author, please follow the link and comment on their blog: Digital Hardcore » rbloggers. offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)