Skip to content

Support cur_column() #951

@mgirlich

Description

@mgirlich

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions