Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for across() #480

Closed
hadley opened this issue Jun 26, 2020 · 2 comments
Closed

Add support for across() #480

hadley opened this issue Jun 26, 2020 · 2 comments
Labels
feature a feature request or enhancement
Milestone

Comments

@hadley
Copy link
Member

hadley commented Jun 26, 2020

No description provided.

@shntnu
Copy link

shntnu commented Apr 1, 2021

I think there is still an issue with this functionality; reprex below (dbplyr v2.1.0)

db <- DBI::dbConnect(RSQLite::SQLite(), ":memory:")

iris_df <- head(iris, 2)

iris_db <- dplyr::copy_to(db, iris_df)

vars <- c("Sepal.Length", "Sepal.Width")

f_mutate <- function(d, v) {
  dplyr::mutate(d, dplyr::across(dplyr::all_of(v), floor))
}

f_mutate(iris_df, vars)
#>   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#> 1            5           3          1.4         0.2  setosa
#> 2            4           3          1.4         0.2  setosa

f_mutate(iris_db, vars)
#> Error: object 'v' not found

dplyr::mutate(iris_db, dplyr::across(dplyr::all_of(vars), floor))
#> # Source:   lazy query [?? x 5]
#> # Database: sqlite 3.34.1 [:memory:]
#>   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#>          <int>       <int>        <int>       <int>   <int>
#> 1            5           3            1           0       0
#> 2            4           3            1           0       0

Created on 2021-04-01 by the reprex package (v1.0.0)

@klaapbakken
Copy link

klaapbakken commented Oct 23, 2021

I've also encountered the problem described by @shntnu here. If anyone else stumbles across this issue I was able to work around it by either having v available in the global environment or by using across(all_of(local(v, env), as shown below. This is dbplyr 2.1.1 by the way.

db <- DBI::dbConnect(RSQLite::SQLite(), ":memory:")

iris_df <- head(iris, 2)

iris_db <- dplyr::copy_to(db, iris_df)

vars <- c("Sepal.Length", "Sepal.Width")

f_mutate <- function(d, v) {
  dplyr::mutate(d, dplyr::across(dplyr::all_of(v), floor))
}

f_mutate_2 <- function(d, v) {
  env <- rlang::current_env()
  dplyr::mutate(d, dplyr::across(dplyr::all_of(local(v, env)), floor))
}

f_mutate(iris_db, vars)
#> Error: object 'v' not found

f_mutate_2(iris_db, vars)
#> # Source:   lazy query [?? x 5]
#> # Database: sqlite 3.36.0 [:memory:]
#>   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#>          <int>       <int>        <dbl>       <dbl> <chr>  
#> 1            5           3          1.4         0.2 setosa 
#> 2            4           3          1.4         0.2 setosa

Created on 2021-10-23 by the reprex package (v2.0.1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

3 participants