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

across() does not work for formula interface #525

Closed
lorenzwalthert opened this issue Oct 21, 2020 · 4 comments · Fixed by #578
Closed

across() does not work for formula interface #525

lorenzwalthert opened this issue Oct 21, 2020 · 4 comments · Fixed by #578
Labels
bug an unexpected problem or unintended behavior verb trans 🤖 Translation of dplyr verbs to SQL

Comments

@lorenzwalthert
Copy link
Contributor

lorenzwalthert commented Oct 21, 2020

Similar to #518, but specifically related to the formula interface. With the devel version of dbplyr and the CRAN version of dplyr.

library(dplyr)
#> Warning: package 'dplyr' was built under R version 4.0.2
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
# works
iris %>% 
  dbplyr::memdb_frame() %>%
  mutate(across(matches("Sepal"), log)) %>%
  invisible()

# does not work
iris %>% 
  dbplyr::memdb_frame() %>%
  mutate(across(matches("Sepal"), ~log(.x)))
#> Error: Unsupported `.fns` for dbplyr::across()

iris %>% 
  dbplyr::memdb_frame() %>%
  mutate(across(matches("Sepal"), ~log(.)))
#> Error: Unsupported `.fns` for dbplyr::across()


# these all work in-memory 
iris %>% 
  # dbplyr::memdb_frame() %>%
  mutate(across(matches("Sepal"), ~log(.))) %>%
  invisible()

iris %>% 
  # dbplyr::memdb_frame() %>%
  mutate(across(matches("Sepal"), ~log(.x))) %>%
  invisible()

Created on 2020-10-21 by the reprex package (v0.3.0)

Session info
devtools::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value                       
#>  version  R version 4.0.0 (2020-04-24)
#>  os       macOS Catalina 10.15.6      
#>  system   x86_64, darwin17.0          
#>  ui       X11                         
#>  language (EN)                        
#>  collate  en_US.UTF-8                 
#>  ctype    en_US.UTF-8                 
#>  tz       Europe/Zurich               
#>  date     2020-10-21                  
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version     date       lib source                             
#>  assertthat    0.2.1       2019-03-21 [1] CRAN (R 4.0.0)                     
#>  backports     1.1.10      2020-09-15 [1] CRAN (R 4.0.2)                     
#>  bit           1.1-15.2    2020-02-10 [1] CRAN (R 4.0.0)                     
#>  bit64         0.9-7       2017-05-08 [1] CRAN (R 4.0.0)                     
#>  blob          1.2.1       2020-01-20 [1] CRAN (R 4.0.0)                     
#>  callr         3.5.0       2020-10-08 [1] CRAN (R 4.0.0)                     
#>  cli           2.1.0       2020-10-12 [1] CRAN (R 4.0.2)                     
#>  crayon        1.3.4       2017-09-16 [1] CRAN (R 4.0.0)                     
#>  DBI           1.1.0       2019-12-15 [1] CRAN (R 4.0.0)                     
#>  dbplyr        1.99.0.9000 2020-10-21 [1] Github (tidyverse/dbplyr@8e63f33)  
#>  desc          1.2.0       2018-05-01 [1] CRAN (R 4.0.0)                     
#>  devtools      2.3.2       2020-09-18 [1] CRAN (R 4.0.2)                     
#>  digest        0.6.25      2020-02-23 [1] CRAN (R 4.0.2)                     
#>  dplyr       * 1.0.2       2020-08-18 [1] CRAN (R 4.0.2)                     
#>  ellipsis      0.3.1       2020-05-15 [1] CRAN (R 4.0.0)                     
#>  evaluate      0.14        2019-05-28 [1] CRAN (R 4.0.0)                     
#>  fansi         0.4.1       2020-01-08 [1] CRAN (R 4.0.0)                     
#>  fs            1.5.0       2020-07-31 [1] CRAN (R 4.0.2)                     
#>  generics      0.0.2       2018-11-29 [1] CRAN (R 4.0.0)                     
#>  glue          1.4.2       2020-08-27 [1] CRAN (R 4.0.2)                     
#>  highr         0.8         2019-03-20 [1] CRAN (R 4.0.0)                     
#>  htmltools     0.5.0       2020-06-16 [1] CRAN (R 4.0.0)                     
#>  knitr         1.30        2020-09-22 [1] CRAN (R 4.0.2)                     
#>  lifecycle     0.2.0       2020-03-06 [1] CRAN (R 4.0.0)                     
#>  magrittr    * 1.5.0.9000  2020-09-28 [1] Github (tidyverse/magrittr@0221e18)
#>  memoise       1.1.0       2017-04-21 [1] CRAN (R 4.0.0)                     
#>  pillar        1.4.6       2020-07-10 [1] CRAN (R 4.0.0)                     
#>  pkgbuild      1.1.0       2020-07-13 [1] CRAN (R 4.0.2)                     
#>  pkgconfig     2.0.3       2019-09-22 [1] CRAN (R 4.0.0)                     
#>  pkgload       1.1.0       2020-05-29 [1] CRAN (R 4.0.0)                     
#>  prettyunits   1.1.1       2020-01-24 [1] CRAN (R 4.0.0)                     
#>  processx      3.4.4       2020-09-03 [1] CRAN (R 4.0.2)                     
#>  ps            1.4.0       2020-10-07 [1] CRAN (R 4.0.2)                     
#>  purrr         0.3.4       2020-04-17 [1] CRAN (R 4.0.0)                     
#>  R6            2.4.1       2019-11-12 [1] CRAN (R 4.0.0)                     
#>  Rcpp          1.0.5       2020-07-06 [1] CRAN (R 4.0.0)                     
#>  remotes       2.2.0       2020-07-21 [1] CRAN (R 4.0.2)                     
#>  rlang         0.4.8       2020-10-08 [1] CRAN (R 4.0.2)                     
#>  rmarkdown     2.3         2020-06-18 [1] CRAN (R 4.0.2)                     
#>  rprojroot     1.3.2.9000  2020-10-18 [1] local                              
#>  RSQLite       2.2.0       2020-01-07 [1] CRAN (R 4.0.0)                     
#>  sessioninfo   1.1.1       2018-11-05 [1] CRAN (R 4.0.0)                     
#>  stringi       1.5.3       2020-09-09 [1] CRAN (R 4.0.2)                     
#>  stringr       1.4.0       2019-02-10 [1] CRAN (R 4.0.0)                     
#>  testthat      2.3.2       2020-03-02 [1] CRAN (R 4.0.0)                     
#>  tibble        3.0.4       2020-10-12 [1] CRAN (R 4.0.2)                     
#>  tidyselect    1.1.0       2020-05-11 [1] CRAN (R 4.0.0)                     
#>  usethis     * 1.6.3       2020-09-17 [1] CRAN (R 4.0.2)                     
#>  vctrs         0.3.4       2020-08-29 [1] CRAN (R 4.0.2)                     
#>  withr         2.3.0       2020-09-22 [1] CRAN (R 4.0.2)                     
#>  xfun          0.18        2020-09-29 [1] CRAN (R 4.0.2)                     
#>  yaml          2.2.1       2020-02-01 [1] CRAN (R 4.0.0)                     
#> 
#> [1] /Library/Frameworks/R.framework/Versions/4.0/Resources/library
@nviets

This comment has been minimized.

@hadley

This comment has been minimized.

@hadley
Copy link
Member

hadley commented Jan 21, 2021

Somewhat more minimal reprex:

library(dbplyr)
library(dplyr, warn.conflicts = FALSE)

db <- memdb_frame(x = 1:5, y = 1:5)
db %>% mutate(across(everything(), ~log(.x)))
#> Error: Unsupported `.fns` for dbplyr::across()

Created on 2021-01-21 by the reprex package (v0.3.0.9001)

@hadley hadley added bug an unexpected problem or unintended behavior verb trans 🤖 Translation of dplyr verbs to SQL labels Jan 21, 2021
@nviets
Copy link

nviets commented Jan 21, 2021

I have the same issue with dbplyr:

tibble(x = 1:5, y = 1:5) %>% 
  summarise(across(where(is.numeric), ~min(.x, na.rm = TRUE)))
# A tibble: 1 x 2
#       x     y
#   <int> <int>
#  1     1     1

db <- memdb_frame(x = 1:5, y = 1:5)
db %>% summarise(across(where(is.numeric), ~min(.x, na.rm = TRUE)))
# Error: Can't rename variables in this context.
# Run `rlang::last_error()` to see where the error occurred.

hadley added a commit that referenced this issue Jan 21, 2021
Now handles `across()` using NSE approach that's more in keeping with the keeping with the rest of dbplyr's translation, so that functions without native translation are passed along. It also gains support for `.fns = NULL` and for translating functions.

Fixes #525. Fixes #534. Fixes #554.
hadley added a commit that referenced this issue Jan 21, 2021
Now handles across() using NSE approach that's more in keeping with the keeping with the rest of dbplyr's translation, so that functions without native translation are passed along. It also gains support for .fns = NULL and for translating functions.

Fixes #525. Fixes #534. Fixes #554.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior verb trans 🤖 Translation of dplyr verbs to SQL
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants