collect_extracts() for workflow_set
I noticed that workflowsets do not appear to have a method for collecting extracts and it have a method for collecting notes https://github.com/tidymodels/workflowsets/issues/135.
class(results) [1] "workflow_set" "tbl_df" "tbl" "data.frame" collect_extracts(results) Error in
collect_extracts(): ! Nocollect_extracts()exists for a <workflow_set/tbl_df/tbl/data.frame> object. Runrlang::last_trace()to see where the error occurred.
It would be handy to have collect_extracts implemented so that you can get elapsed time or other information extracted.
Here one example using partials if you want to reuse the code for mulitple collect_*
my_collect_custom <- function(wflow_set_results, fn){
wflow_set_rsl <- wflow_set_results %>%
dplyr::select(wflow_id, result)
distinct_list_of_workflows <- wflow_set_rsl %>%
dplyr::select(wflow_id) %>%
distinct() %>%
pull(wflow_id)
collect_fn_helper <- function(x){
wflow_set_rsl %>%
filter(wflow_id == x) %>%
pull(result) %>%
pluck(1) %>%
fn()
}
list_dfs <- map_dfr(
set_names(distinct_list_of_workflows),
collect_fn_helper,
.id = "workflow_id")
list_dfs
}
my_collect_extracts <- purrr::partial(my_collect_custom, fn = collect_extracts)
my_collect_extracts(results)
my_collect_notes <- purrr::partial(my_collect_custom, fn = collect_notes)
my_collect_notes(results)
Yup, totally on board. Thanks for the issue. Will try to carve out time for this next time I'm focused on workflowsets!
Could I help with a PR or do you have some refactoring in mind?
I'm not focused on the package at the moment and will revisit once I sit down with the package for a day or two, but you're welcome to give the PR a go in the meantime!
Closed by https://github.com/tidymodels/workflowsets/pull/161