Following on from questions here and here, I'm trying to get the latest version of multidplyr
to work with a custom function.
By way of reproducible example, I have tried:
library(multidplyr)
library(dplyr)
cl <- new_cluster(3)
df <- data.frame(Grp = rep(LETTERS[1:3], each = 4), Val = rep(3:1, 4))
cust_func <- function (x) {
x + 1
}
cluster_copy(cl, "cust_func")
df_clust <- df %>%
group_by(Grp) %>%
partition(cl)
df_clust %>%
mutate(Add1 = cust_func(Val)) %>%
collect()
But I get a Computation failed
error. I have tried different ordering and a few other minor variations but no luck.
Is it possible to export custom functions to the clusters in the latest version of multidplyr
? If so, how?