I want to use multidplyr, and it has yet to have anything for summarise_at. i have hundreds if not thousands, so the summarise_at is necessary, but unfortunately, not available in multidplyr.
looking for an alternative to work around it.
library('tidyverse')
df <- tibble(ID = c('a','a','b','c','c','e','e','f','g','g'),
var1 = floor(runif(10, min=0, max=100)),
var2 = floor(runif(10, min=0, max=100)),
var3 = floor(runif(10, min=0, max=100)),
var4 = floor(runif(10, min=0, max=100))
)
library('multidplyr')
cluster <- new_cluster(5)
#works
df %>%
group_by(ID) %>%
#partition(cluster) %>%
summarise_at(.vars = vars(starts_with('var')),sum)
#collect()
#works
df %>%
group_by(ID) %>%
partition(cluster) %>%
summarise(var1 = sum(var1),
var2 = sum(var2),
var3 = sum(var3)) %>%
collect()
#doesnt works
df %>%
group_by(ID) %>%
partition(cluster) %>%
summarise_at(.vars = vars(starts_with('var')),sum) %>%
collect()
I've even tried this
#Define character string vector to replace command line
sum_var <- select(df,starts_with('var')) %>% names()
sum_var_str <- paste0(sum_var," = sum(",sum_var,")")
sum_var_str <- str_c(sum_var_str, collapse = ", ")
> sum_var
[1] "var1" "var2" "var3" "var4"
> sum_var_str
[1] "var1 = sum(var1), var2 = sum(var2), var3 = sum(var3), var4 = sum(var4)"
#works
df %>%
group_by(ID) %>%
{ eval(parse(text = sprintf("summarise(., %s, .groups = 'drop')", sum_var_str))) }
#doesn't works
df %>%
group_by(ID) %>%
partition(cluster) %>%
{ eval(parse(text = sprintf("summarise(., %s, .groups = 'drop')", sum_var_str))) } %>%
collect()
Found the solution