Description Usage Arguments Details Value See Also Examples
View source: R/add_case_when.R
add_case_when
is useful when you have previously created a case_when
function with create_case_when()
and want to use it against a database
with dbplyr.
1 | add_case_when(con, ...)
|
con |
A DBIConnection object. |
... |
Not used. |
In order to be safely used with a pipe, add_case_when
does not throw any
error. In case of internal error, the original connection object is returned
with warning.
A new DBIConnection object with a customised translation.
create_case_when, create_sql_case_when
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 | if (requireNamespace("RSQLite", quietly = TRUE)) {
library(dplyr)
cw_fb <- create_case_when(
number %% 35 == 0 ~ "fizz buzz",
number %% 5 == 0 ~ "fizz",
number %% 7 == 0 ~ "buzz",
TRUE ~ as.character(number),
vars = "number"
)
con <-
DBI::dbConnect(RSQLite::SQLite(), ":memory:") %>%
add_case_when(cw_fb)
# You can print con to retrieve informations about custom translation
con
numbers <- copy_to(con, data.frame(x = 1:50, y = 51:100), "numbers")
fizzbuzz <-
numbers %>%
mutate(fb_x = cw_fb(x), fb_y = cw_fb(y))
fizzbuzz %>% show_query()
fizzbuzz %>% collect()
DBI::dbDisconnect(con)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.