sql: Create SQL 'SELECT' and 'UPDATE' statements

Description Usage Arguments Details Value See Also Examples

View source: R/coding.R

Description

Helper function converting R code into SQL SELECT statements and data frames into UPDATE statements.

Usage

1
2
3
4
5
6
7
8
  sql(x, ...)

  ## S3 method for class 'data.frame'
 sql(x, where, table,
    set = setdiff(colnames(x), where), ...)

  ## S3 method for class 'formula'
 sql(x, ...)

Arguments

x

Data frame or formula.

where

Character vector giving the name of the data frame and database table columns used to select rows.

table

Character scalar indicating the name of the database table to be updated.

set

Character vector giving the name of the data frame and database table columns to be updated.

...

Optional arguments passed between methods.

Details

The formula method saves some typing, particularly in the case of complex queries, but it does not support joins. R operators are mostly directly translated except for those with the highest precedence. Infix operators are translated literally. The control structures if and function yield CASE constructs.

To use the data frame method to update a column, say, "x" that is also used to select rows, include "x" in the where argument and "new.x" in the set argument.

Value

Character vector.

See Also

Other coding-functions: L, LL, assert, case, check, collect, contains, flatten, listing, map_names, map_values, must, set, unnest

Examples

1
2
3
4
5
6
## formula method
x <- mytable(a, b, if (c1 > 15 | c2 == NULL) c1 else c2) ~
  b < 69 & a %in% {"x"
    "y"}
(y <- sql(x))
stopifnot(is.character(y), length(y) == 1L)

pkgutils documentation built on May 2, 2019, 5:49 p.m.

Related to sql in pkgutils...