Learn R Programming

rEHR (version 1.0)

select_events: Extracts From the database

Description

This is a generic function for extracting EHR data from the database

Usage

select_events(db = NULL, tab, columns = "*", where = NULL, sql_only = FALSE, convert_dates = FALSE)

Arguments

db
a database connection
tab
the database table to extract from
columns
character vector of columns to extract from the table "*" means all tables
where
string representation of the selection criteria
sql_only
logical should the function just return a string of the SQL query?
convert_dates
logical should date fields be converted to R date format?

Value

a dataframe or a string representing an sql query

Details

The function is the base function for a range of others It can either extract by itself or generate the SQL to make a query. In this way it can be combined to make compound queries. The where argument is equivalent to the WHERE clause in sql The elements are converted to SQL using dplyr::translate_sql_ If an element is wrapped in a `.()`, the element is expanded. Dates should be entered as strings in ISO format (

Examples

Run this code
## Not run: 
# # medical lookup tables are provided with CPRD
# load("data/medical.RData")
# a <- read.csv("data/chronic-renal-disease.csv")
# a <- read_to_medcodes(a, medical, "code", lookup_readcodes= "readcode", 
# lookup_medcodes="medcode", description = T)
# b <- select_events(db, tab = "Referral", columns = c("patid", "eventdate", "medcode"), 
# where = "medcode %in% .(a$medcode) & eventdate < '2000-01-01'")
# b1 <- select_events(db, tab = "Clinical", columns = c("patid", "eventdate", "medcode"), 
# where = "medcode %in% .(a$medcode) & eventdate < '2000-01-01'")
# ## End(Not run)

Run the code above in your browser using DataLab