I tried to use across() to apply some custom sql to multiple columns. But I had no luck with it.
library(dbplyr)
library(dplyr, warn.conflicts = FALSE)
iris %>%
slice(1:2) %>%
transmute(across(1:2, ~ sql(paste0(cur_column(), "::jsonb"))))
#> Sepal.Length Sepal.Width
#> 1 <SQL> Sepal.Length::jsonb <SQL> Sepal.Width::jsonb
#> 2 <SQL> Sepal.Length::jsonb <SQL> Sepal.Width::jsonb
iris_db <- tbl_memdb(iris)
iris_db %>%
transmute(across(1:2, ~ sql(paste0(cur_column(), "::jsonb")))) %>%
show_query()
#> <SQL>
#> SELECT
#> cur_column() || '::jsonb' AS `Sepal.Length`,
#> cur_column() || '::jsonb' AS `Sepal.Width`
#> FROM `iris`
iris_db %>%
transmute(across(1:2, ~ sql(!!paste0(cur_column(), "::jsonb")))) %>%
show_query()
#> Error in `cur_column()`:
#> ! Must be used inside `across()`.
Created on 2022-07-29 by the reprex package (v2.0.1)
I tried to use
across()to apply some custom sql to multiple columns. But I had no luck with it.Created on 2022-07-29 by the reprex package (v2.0.1)