markfairbanks / tidytable

Tidy interface to 'data.table'
https://markfairbanks.github.io/tidytable/
Other
450 stars 32 forks source link

across doesn't allow for a list with functions #822

Closed bnicenboim closed 2 months ago

bnicenboim commented 2 months ago
library(tidytable)

Using a list with functions does not work with across.

mean_var <- list(mean = ~ mean(., na.rm = TRUE),
                 var = ~ var(., na.rm = TRUE))
td <- tidytable(a = runif(100), b = runif(100))
td |>  summarize(across(everything(), mean_var))
#> Error in mean_var(a): could not find function "mean_var"

It works in dplyr:


td |> dplyr::summarize(across(everything(), mean_var))
#>      a_mean      a_var    b_mean      b_var
#> 1 0.4836208 0.07956486 0.4964107 0.07229442

Created on 2024-08-30 with reprex v2.1.1

markfairbanks commented 2 months ago

Unfortunately passing a premade list to to across() is something that isn’t possible in tidytable and will always be a limitation of its implementation