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

Cannot detect custom function arguments #317

Closed
psychelzh opened this issue Dec 6, 2021 · 1 comment · Fixed by #318
Closed

Cannot detect custom function arguments #317

psychelzh opened this issue Dec 6, 2021 · 1 comment · Fixed by #318

Comments

@psychelzh
Copy link

See the following example. When translating custom function, the argument g is ignored. Will it be supported?

set.seed(1)
data <- data.frame(g = LETTERS[1:2], x = runif(2))
f <- function(x, g = NULL) {
    x |> 
        dplyr::group_by(dplyr::across(dplyr::all_of(g))) |> 
        dplyr::summarise(mean_x = mean(.data[["x"]]))
}
f(data)
#> # A tibble: 1 x 1
#>   mean_x
#>    <dbl>
#> 1  0.319
data |> 
    dtplyr::lazy_dt() |> 
    f()
#> Error: object 'g' not found
#> Caused by error in `dplyr::all_of()`:
#>   object 'g' not found
f(data, g = "g")
#> # A tibble: 2 x 2
#>   g     mean_x
#>   <chr>  <dbl>
#> 1 A      0.266
#> 2 B      0.372
data |> 
    dtplyr::lazy_dt() |> 
    f(g = "g")
#> Error: object 'g' not found
#> Caused by error in `dplyr::all_of()`:
#>   object 'g' not found

Created on 2021-12-06 by the reprex package (v2.0.1)

Session info
sessioninfo::session_info()
#> - Session info  --------------------------------------------------------------
#>  hash: person juggling: medium-dark skin tone, guard, waving hand: medium skin tone
#> 
#>  setting  value
#>  version  R version 4.1.2 (2021-11-01)
#>  os       Windows 10 x64 (build 22000)
#>  system   x86_64, mingw32
#>  ui       RTerm
#>  language en
#>  collate  Chinese (Simplified)_China.936
#>  ctype    Chinese (Simplified)_China.936
#>  tz       Asia/Taipei
#>  date     2021-12-06
#>  pandoc   2.14.0.3 @ C:/Program Files/RStudio/bin/pandoc/ (via rmarkdown)
#> 
#> - Packages -------------------------------------------------------------------
#>  package     * version     date (UTC) lib source
#>  assertthat    0.2.1       2019-03-21 [1] CRAN (R 4.1.0)
#>  backports     1.4.0       2021-11-23 [1] CRAN (R 4.1.2)
#>  cli           3.1.0       2021-10-27 [1] CRAN (R 4.1.1)
#>  crayon        1.4.2       2021-10-29 [1] CRAN (R 4.1.1)
#>  data.table    1.14.2      2021-09-27 [1] CRAN (R 4.1.1)
#>  DBI           1.1.1       2021-01-15 [1] CRAN (R 4.1.0)
#>  digest        0.6.29      2021-12-01 [1] CRAN (R 4.1.2)
#>  dplyr         1.0.7       2021-06-18 [1] CRAN (R 4.1.0)
#>  dtplyr        1.2.0       2021-12-05 [1] CRAN (R 4.1.2)
#>  ellipsis      0.3.2       2021-04-29 [1] CRAN (R 4.1.0)
#>  evaluate      0.14        2019-05-28 [1] CRAN (R 4.1.0)
#>  fansi         0.5.0       2021-05-25 [1] CRAN (R 4.1.0)
#>  fastmap       1.1.0       2021-01-25 [1] CRAN (R 4.1.0)
#>  fs            1.5.1       2021-11-30 [1] CRAN (R 4.1.2)
#>  generics      0.1.1       2021-10-25 [1] CRAN (R 4.1.1)
#>  glue          1.5.1       2021-11-30 [1] CRAN (R 4.1.2)
#>  highr         0.9         2021-04-16 [1] CRAN (R 4.1.0)
#>  htmltools     0.5.2       2021-08-25 [1] CRAN (R 4.1.1)
#>  knitr         1.36        2021-09-29 [1] CRAN (R 4.1.1)
#>  lifecycle     1.0.1       2021-09-24 [1] CRAN (R 4.1.1)
#>  magrittr      2.0.1       2020-11-17 [1] CRAN (R 4.1.0)
#>  pillar        1.6.4       2021-10-18 [1] CRAN (R 4.1.1)
#>  pkgconfig     2.0.3       2019-09-22 [1] CRAN (R 4.1.0)
#>  purrr         0.3.4       2020-04-17 [1] CRAN (R 4.1.0)
#>  R.cache       0.15.0      2021-04-30 [1] CRAN (R 4.1.0)
#>  R.methodsS3   1.8.1       2020-08-26 [1] CRAN (R 4.1.0)
#>  R.oo          1.24.0      2020-08-26 [1] CRAN (R 4.1.0)
#>  R.utils       2.11.0      2021-09-26 [1] CRAN (R 4.1.1)
#>  R6            2.5.1       2021-08-19 [1] CRAN (R 4.1.1)
#>  reprex        2.0.1       2021-08-05 [1] CRAN (R 4.1.0)
#>  rlang         0.99.0.9001 2021-11-29 [1] Github (r-lib/rlang@67da1e1)
#>  rmarkdown     2.11        2021-09-14 [1] CRAN (R 4.1.1)
#>  rstudioapi    0.13        2020-11-12 [1] CRAN (R 4.1.0)
#>  sessioninfo   1.2.1       2021-11-02 [1] CRAN (R 4.1.2)
#>  stringi       1.7.6       2021-11-29 [1] CRAN (R 4.1.2)
#>  stringr       1.4.0       2019-02-10 [1] CRAN (R 4.1.0)
#>  styler        1.6.2       2021-09-23 [1] CRAN (R 4.1.1)
#>  tibble        3.1.6       2021-11-07 [1] CRAN (R 4.1.2)
#>  tidyselect    1.1.1       2021-04-30 [1] CRAN (R 4.1.0)
#>  utf8          1.2.2       2021-07-24 [1] CRAN (R 4.1.0)
#>  vctrs         0.3.8       2021-04-29 [1] CRAN (R 4.1.0)
#>  withr         2.4.3       2021-11-30 [1] CRAN (R 4.1.2)
#>  xfun          0.28        2021-11-04 [1] CRAN (R 4.1.2)
#>  yaml          2.2.1       2020-02-01 [1] CRAN (R 4.1.0)
#> 
#>  [1] C:/Users/liang/Documents/R/win-library/4.1
#>  [2] C:/Program Files/R/R-4.1.2/library
#> 
#> ------------------------------------------------------------------------------
@psychelzh
Copy link
Author

psychelzh commented Aug 15, 2022

@markfairbanks Still fails in such circumstances (seemingly, function calls in functions can not access environment variables, either):

library(dplyr)
#> 
#> 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
library(dtplyr)
f <- function(x, y, .v = "x") {
  inner_join(
    mutate(x, a = .v),
    y,
    by = character()
  )
}
x <- data.frame(a = "y")
y <- data.frame(b = "x")
f(x, y)
#>   a b
#> 1 x x
lazy_dt(x) |> 
  f(y)
#> Error in .checkTypos(e, names_x): Object '.v' not found. Perhaps you intended .cross_join_col

Created on 2022-08-15 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
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant