When creating a package that maps to a new SQL based src, you'll often
want to provide some additional mappings from common R commands to the
commands that your tbl provides. These three functions make that
easy.
The three families of functions than an
SQL variant can supply.
..., .funs
named functions, used to add custom converters from standard
R functions to sql functions. Specify individually in ..., or
provide a list of .funs
.parent
the sql variant that this variant should inherit from.
Defaults to base_sql which provides a standard set of
mappings for the most common operators and functions.
f
the name of the sql function as a string
n
for sql_infix, an optional number of arguments to expect.
Will signal error if not correct.
Helper functions
sql_infix and sql_prefix create default SQL infix and prefix
functions given the name of the SQL function. They don't perform any input
checking, but do correctly escape their input, and are useful for
quickly providing default wrappers for a new SQL variant.
See Also
sql for an example of a more customised sql
conversion function.
Examples
# An example of adding some mappings for the statistical functions that
# postgresql provides: http://bit.ly/K5EdTn
postgres_agg <- sql_translator(.parent = base_agg,
cor = sql_prefix("corr"),
cov = sql_prefix("covar_samp"),
sd = sql_prefix("stddev_samp"),
var = sql_prefix("var_samp")
)
postgres_var <- sql_variant(
base_scalar,
postgres_agg
)
translate_sql(cor(x, y), variant = postgres_var)
translate_sql(sd(income / years), variant = postgres_var)
# Any functions not explicitly listed in the converter will be translated
# to sql as is, so you don't need to convert all functions.
translate_sql(regr_intercept(y, x), variant = postgres_var)