knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "README-" )
Lazy SQL programming.
Helper functions to build SQL statements under program control for use with
dbGetQuery
, dbSendQuery
, sqldf
, etc.
They are intended to increase speed of coding and
to reduce coding errors. Arguments are carefully checked, in particular SQL
identifiers such as names of tables or columns.
Currently implemented are:
date_between
Create SQL string to select date between two given dates.in_condition
Create SQL string to select values included (or not included)
in a set of given values.natural_key
Create SQL string for joining on matching natural keys.More patterns will be added as required.
date1 <- as.Date("2016-02-22") date2 <- as.Date("2016-02-11") # SQL expression for date range (sql_expr1 <- lazysql::date_between("STD_1", c(date1, date2))) # SQL expression for single date (sql_expr2 <- lazysql::date_between("STD_1", date1)) # sample SQL statements paste("select * from TEST_TABLE where", sql_expr1) paste("select * from TEST_TABLE where", sql_expr2)
# SQL expressions lazysql::in_condition("COL_1", 1:3) lazysql::in_condition("COL_1", 1:3, "not") lazysql::in_condition("COL_1", LETTERS[2:3]) lazysql::in_condition("COL_1", LETTERS[2:3], "not")
# SQL expression (sql_expr <- lazysql::natural_key(c("TAB1", "tab_2"),c("COL1", "col_2"))) # sample SQL JOIN statement paste("select * from TAB1, TAB2 where", sql_expr)
Get the released version from CRAN:
install.packages("lazysql")
Get the development version from github:
if (!"devtools" %in% installed.packages()) install.packages("devtools") devtools::install_github("UweBlock/lazysql")
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.