From 445d65f42824a2fd00f001ac9986617b88fa97bf Mon Sep 17 00:00:00 2001 From: mitchelloharawild Date: Fri, 13 Sep 2024 21:36:41 +1000 Subject: [PATCH] Improve mdl_df_apply for extra key variables of mable --- R/utils.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/utils.R b/R/utils.R index 1b1ca357..e9231edb 100644 --- a/R/utils.R +++ b/R/utils.R @@ -325,8 +325,9 @@ dist_types <- function(dist) { mdl_df_apply <- function(x, f, ...) { mbl_vars <- mable_vars(x) + kv <- key_vars(x) x <- mutate(as_tibble(x), dplyr::across(all_of(mbl_vars), function(x) lapply(x, f, ...))) x <- pivot_longer(x, all_of(mbl_vars), names_to = ".model", values_to = "__results__") - unnest_tsbl(x, "__results__", parent_key = ".model") + unnest_tsbl(x, "__results__", parent_key = c(kv, ".model")) }