knitr::opts_chunk$set( collapse = TRUE, comment = "#>", eval = TRUE )
The package is only on github and can be installed by using
if (!require("drat")) { install.packages("drat") library(drat) } drat::addRepo("LEEF-UZH") install.packages("LEEF.analysis")
library(LEEF.analysis) library(dplyr)
set the database:
options(RRDdb = "/Volumes/LEEF/0.RRD/LEEF.RRD.sqlite")
All build-in functions to read the data (i.e. read_sql()
, read_rrd()
(should not be used aymore), db_read_density()
and db_read_o2()
) access the database in READ ONLY mode and do not pose any danger of corrupting the data. Using functions from the DBI
package, can be destructive and shluld be avoided!
The densities can be read by using
db_read_density()
This returns an object which can be piped through dplyr
functions and only contains a link to the database. In most cases, dplyr is creating an SQL query which is than send to the database. Data is only fetched when needed, or explicitely by using
db_read_density() %>% collect()
Nearly all filtering is done in the SQLite database, which accelerates the acces as you can see by comparing the following, while the result is the same:
system.time( x <- db_read_density() %>% select(timestamp, day) %>% distinct() %>% collect() ) x
system.time( x <- db_read_density() %>% collect() %>% select(timestamp, day) %>% distinct() ) x
A second convenience function reads the O2 measurements:
db_read_o2()
The same rules as for the function db_read_density()
apply here.
You can also use SQL syntax to read from the RRD database by using the function db_read_sql()
. This gives you a huge amount of flexibility as you can specify the sql syntax as an argument. In contrast to the functions mentioned above, this functions returns a data.frame
of the data, and all filtering and processing after wards is done locally. For example:
read_sql(sql = "SELECT * FROM density") %>% filter (as.integer(timestamp) >= as.integer(20210920)) %>% filter (as.integer(timestamp) <= as.integer(21000101))
which is the same as
db_read_density() %>% collect()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.