Closed tungttnguyen closed 1 year ago
As tidytable
is currently constructed you have to pass the list()
call inside of across()
to work.
pacman::p_load(tidytable)
df <- tidytable(x = 1:3, y = 4:6)
# Works
df %>%
summarize(across(everything(), list(mean = mean, max = max)))
#> # A tidytable: 1 × 4
#> x_mean x_max y_mean y_max
#> <dbl> <int> <dbl> <int>
#> 1 2 3 5 6
# Fails
fn_list <- list(mean = mean, max = max)
df %>%
summarize(across(everything(), fn_list))
#> Error in fn_list(x): could not find function "fn_list"
I'll take a look and see if I can get it to work more like dplyr
.
As
tidytable
is currently constructed you have to pass thelist()
call inside ofacross()
to work.pacman::p_load(tidytable) df <- tidytable(x = 1:3, y = 4:6) # Works df %>% summarize(across(everything(), list(mean = mean, max = max))) #> # A tidytable: 1 × 4 #> x_mean x_max y_mean y_max #> <dbl> <int> <dbl> <int> #> 1 2 3 5 6 # Fails fn_list <- list(mean = mean, max = max) df %>% summarize(across(everything(), fn_list)) #> Error in fn_list(x): could not find function "fn_list"
I'll take a look and see if I can get it to work more like
dplyr
.
Thanks Mark!
I took a look at this - basically the change required to make this work would break some really common use cases.
Here are a couple examples (that currently work correctly in tidytable):
# Using another column within the function
mutate(
across(c(x, y), ~ .x + y)
)
# Using context functions like n()/row_number()
mutate(
across(c(x, y), ~ .x + n())
)
There are a couple other use cases that wouldn't work as well.
Passing a pre-made list of functions to across()
is going to have to be one of those things that is a limit of tidytable.
Hello Mark,
I couldn't get the following example to work with
tidytable
. It worked withdplyr
so I am not sure what the problem was.Define a list of functions
dplyr
tidytable
Created on 2023-03-10 with reprex v2.0.2