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.
- # connect to the sqlite file
- con = dbConnect(drv="SQLite", dbname="country.sqlite")
- # get a list of all tables
- alltables = dbListTables(con)
- # get the populationtable as a data.frame
- p1 = dbGetQuery( con,'select * from populationtable' )
- # count the areas in the SQLite table
- p2 = dbGetQuery( con,'select count(*) from areastable' )
- # find entries of the DB from the last week
- p3 = dbGetQuery(con, "SELECT population WHERE DATE(timeStamp) < DATE('now', 'weekday 0', '-7 days')")
- #Clear the results of the last query
- #Select population with managerial type of job
- p4 = dbGetQuery(con, "select * from populationtable where jobdescription like '%manager%'")