Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #156: Feature collect_extracts #161

Merged
merged 5 commits into from
Aug 27, 2024

Conversation

jrosell
Copy link
Contributor

@jrosell jrosell commented Aug 13, 2024

I added collect_extracts method to the workflow_set objects.

As I run the tests, I seen some of them failing too. This is why I added some changes to test-fit_best.R and test-collect-notes.R too.

Copy link
Contributor

@simonpcouch simonpcouch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking super strong! I definitely think you made the right move of starting with collect_notes() and mirroring the structure.

One hiccup here is that the .extracts column won't always be around unless the user supplies an extract function. If they don't, they'll see:

library(tidymodels)

set.seed(1)
folds <- rsample::vfold_cv(mtcars, v = 3)

wflow_set <-
   workflow_set(
      list(reg = mpg ~ ., nonlin = mpg ~ wt + 1 / sqrt(disp)),
      list(lm = parsnip::linear_reg())
   )

wflow_set_trained <-
   wflow_set %>%
   workflow_map("fit_resamples", resamples = folds)

collect_extracts(wflow_set_trained)
#> Error in `dplyr::mutate()`:
#> ℹ In argument: `extracts = list(collect_extracts(result))`.
#> ℹ In row 1.
#> Caused by error in `collect_extracts()`:
#> ! The `.extracts` column does not exist.
#> ℹ Please supply a control object (`?tune::control_grid()`) with a non-`NULL`
#>   `extract` argument during resample fitting.

Created on 2024-08-15 with reprex v2.1.1

All of the dplyr::mutate() error context is a bit distracting / confusing, but I don't think it's worth the complexity of trying to catch and rethrow—let's stick with the approach you've proposed. That said, could you add a snapshot test for the case where the user doesn't supply an extract function but tries to collect_extracts()?

Also, could you add a NEWS entry advertising your changes?

Copy link
Contributor

@simonpcouch simonpcouch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks so much!

tests/testthat/test-collect-extracts.R Outdated Show resolved Hide resolved
tests/testthat/test-collect-extracts.R Outdated Show resolved Hide resolved
@simonpcouch simonpcouch merged commit 11b70d1 into tidymodels:main Aug 27, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants