workflowsets icon indicating copy to clipboard operation
workflowsets copied to clipboard

collect_extracts() for workflow_set

Open jrosell opened this issue 1 year ago • 3 comments

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(): ! No collect_extracts() exists for a <workflow_set/tbl_df/tbl/data.frame> object. Run rlang::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)

jrosell avatar Jun 06 '24 23:06 jrosell

Yup, totally on board. Thanks for the issue. Will try to carve out time for this next time I'm focused on workflowsets!

simonpcouch avatar Jun 07 '24 15:06 simonpcouch

Could I help with a PR or do you have some refactoring in mind?

jrosell avatar Jul 24 '24 16:07 jrosell

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!

simonpcouch avatar Jul 29 '24 13:07 simonpcouch

Closed by https://github.com/tidymodels/workflowsets/pull/161

jrosell avatar Aug 27 '24 21:08 jrosell