1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
|
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/translate-sql-string.R,
% R/translate-sql-paste.R, R/translate-sql-helpers.R, R/backend-.R,
% R/backend-odbc.R
\docType{data}
\name{sql_substr}
\alias{sql_substr}
\alias{sql_str_sub}
\alias{sql_paste}
\alias{sql_paste_infix}
\alias{sql_variant}
\alias{sql_translator}
\alias{sql_infix}
\alias{sql_prefix}
\alias{sql_aggregate}
\alias{sql_aggregate_2}
\alias{sql_aggregate_n}
\alias{sql_not_supported}
\alias{sql_cast}
\alias{sql_try_cast}
\alias{sql_log}
\alias{sql_cot}
\alias{base_scalar}
\alias{base_agg}
\alias{base_win}
\alias{base_no_win}
\alias{base_odbc_scalar}
\alias{base_odbc_agg}
\alias{base_odbc_win}
\title{Create an sql translator}
\usage{
sql_substr(f = "SUBSTR")
sql_str_sub(subset_f = "SUBSTR", length_f = "LENGTH", optional_length = TRUE)
sql_paste(default_sep, f = "CONCAT_WS")
sql_paste_infix(default_sep, op, cast)
sql_variant(
scalar = sql_translator(),
aggregate = sql_translator(),
window = sql_translator()
)
sql_translator(..., .funs = list(), .parent = new.env(parent = emptyenv()))
sql_infix(f, pad = TRUE)
sql_prefix(f, n = NULL)
sql_aggregate(f, f_r = f)
sql_aggregate_2(f)
sql_aggregate_n(f, f_r = f)
sql_not_supported(f)
sql_cast(type)
sql_try_cast(type)
sql_log()
sql_cot()
base_scalar
base_agg
base_win
base_no_win
base_odbc_scalar
base_odbc_agg
base_odbc_win
}
\arguments{
\item{f}{the name of the sql function as a string}
\item{scalar, aggregate, window}{The three families of functions than an
SQL variant can supply.}
\item{..., .funs}{named functions, used to add custom converters from standard
R functions to sql functions. Specify individually in \code{...}, or
provide a list of \code{.funs}}
\item{.parent}{the sql variant that this variant should inherit from.
Defaults to \code{base_agg} which provides a standard set of
mappings for the most common operators and functions.}
\item{pad}{If \code{TRUE}, the default, pad the infix operator with spaces.}
\item{n}{for \code{sql_infix()}, an optional number of arguments to expect.
Will signal error if not correct.}
\item{f_r}{the name of the r function being translated as a string}
}
\description{
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.
}
\section{Helper functions}{
\code{sql_infix()} and \code{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.
}
\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_aggregate_2("CORR"),
cov = sql_aggregate_2("COVAR_SAMP"),
sd = sql_aggregate("STDDEV_SAMP", "sd"),
var = sql_aggregate("VAR_SAMP", "var")
)
# Next we have to simulate a connection that uses this variant
con <- simulate_dbi("TestCon")
sql_translation.TestCon <- function(x) {
sql_variant(
base_scalar,
postgres_agg,
base_no_win
)
}
translate_sql(cor(x, y), con = con, window = FALSE)
translate_sql(sd(income / years), con = con, window = FALSE)
# 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), con = con)
}
\seealso{
\code{\link[=win_over]{win_over()}} for helper functions for window functions.
\code{\link[=sql]{sql()}} for an example of a more customised sql
conversion function.
}
\keyword{datasets}
\keyword{internal}
|