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 doesn't handle dynamically created function list #471

Closed
FinYang opened this issue May 7, 2024 · 1 comment
Closed

across doesn't handle dynamically created function list #471

FinYang opened this issue May 7, 2024 · 1 comment

Comments

@FinYang
Copy link

FinYang commented May 7, 2024

across doesn't handle a list of functions created inside the across call. See reprex below.

library(dtplyr)
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
tibble(a = 1) %>% 
  lazy_dt() %>% 
  mutate(across(a, lapply(1:2, \(x) identity))) %>% 
  as_tibble()
#> Error in `across_funs()`:
#> ! `.fns` argument to dtplyr::across() must be a NULL, a function, formula, or list

Created on 2024-05-07 with reprex v2.1.0

Inside acrosss_funs, a list of functions is identified using call name list, so it wouldn't work with lists of functions created in other way.

} else if (is_call(funs, "list")) {

The creation is evaluated once later, but after the evaluation, it's passed through the same function across_fus, which again ignores the list if it's not a call named list.

} else if (!is.null(env)) {
# Try evaluating once, just in case
funs <- eval(funs, env)
return(across_funs(funs, NULL, j = j, dots = dots, names_spec = NULL, fn = fn))
} else {
abort("`.fns` argument to dtplyr::across() must be a NULL, a function, formula, or list")
}

BTW, is "dtplyr::across" in the error message intentional?

@markfairbanks
Copy link
Collaborator

markfairbanks commented May 8, 2024

Unfortunately this is a limit of the translation - you need to supply it an explicit list call of what you want to apply

Edit: This was also discussed a little bit here #154 (comment)

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

No branches or pull requests

2 participants