redivis$connect_dbi
redivis$connect_dbi() → DBI::DBIConnection
Returns a DBI connection that can be used by dbplyr and other interfaces that work with DBI. This connection will be globally scoped, and all table names must be appropriately qualified.
To create a connection scoped to particulary dataset or workflow, see:
Returns:
Examples
con <- redivis$connect_dbi()
tbl(con, "demo.ghcn_daily_weather_data.stations") |> filter(latitude > 0) |> collect()
# Prints a tibble with the relevant weather stationsSupported dplyr functions
DBI connections can be used with all of the standard dplyr verbs (filter(), mutate(), summarise(), joins, etc.). Within these verbs, the following R functions are translated to Redivis SQL:
Math and operators
+, -, *, /, ^, %%, %/%, %||%, abs(), sqrt(), exp(), log(), log2(), log10(), round(), floor(), ceiling(), pmin(), pmax()
Type conversion
as.integer(), as.numeric(), as.double(), as.character(), as.logical(), as.Date(), as.POSIXct(), lubridate::as_date(), lubridate::as_datetime()
Conditionals
ifelse(), if_else(), case_when(), coalesce(), is.na(), between(), %in%
Strings
nchar(), tolower(), toupper(), trimws(), paste(), paste0(), substr(), substring(), startsWith(), endsWith(), grepl(), sub(), gsub(), and from stringr: str_detect(), str_starts(), str_ends(), str_extract(), str_replace(), str_replace_all(), str_remove(), str_remove_all(), str_trim(), str_squish(), str_pad(), str_to_lower(), str_to_upper(), str_to_title(), str_c(), str_length(), str_sub()
Dates and times
Sys.Date(), Sys.time(), difftime(), and from lubridate: today(), now(), year(), isoyear(), quarter(), month(), week(), isoweek(), day(), mday(), yday(), wday(), hour(), minute(), second(), floor_date(), and from clock: get_year(), get_month(), get_day(), get_hour(), get_minute(), get_second(), add_days(), add_weeks(), add_months(), add_quarters(), add_years(), date_build(), date_count_between()
Aggregates
n(), n_distinct(), sum(), mean(), min(), max(), sd(), var(), cor(), cov(), median(), quantile(), any(), all(), and from stringr: str_flatten()
Window functions
row_number(), min_rank(), rank(), dense_rank(), lead(), lag(), first(), last(), cumsum(), and the aggregate functions above (other than median(), quantile(), n_distinct(), str_flatten(), any(), all(), cor(), and cov())
The following differences from R's behavior apply:
%/%and%%round toward negative infinity, as in R, and always return a double.median()andquantile()are approximate.quantile()takes a singleprobsvalue.str_replace(),str_remove(), andsub()replace only the first match, and require a literal pattern and a replacement without backreferences. To use a column as the pattern, or to use backreferences, usestr_replace_all()orgsub()to replace every match.difftime()only supportsunits = "days", anddate_count_between()only supports aprecisionof"day"or"week".month()andwday()don't supportlabel = TRUE, andwday()only supportsweek_start = 7.floor_date()doesn't support multiples of a unit (e.g.,"2 days").second()returns whole seconds.Redivis
dateTimevariables don't have a time zone, soas.POSIXct()andSys.time()produce aDATETIME, and RPOSIXctvalues used within a query are converted to UTC.
An error will be raised if a function is called with arguments that can't be translated.
Last updated
Was this helpful?

