Skip to content

Commit

Permalink
Improve mdl_df_apply for extra key variables of mable
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchelloharawild committed Sep 13, 2024
1 parent b61d4bf commit 445d65f
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}

0 comments on commit 445d65f

Please sign in to comment.