Skip to content

Commit

Permalink
allow explicit specification of strata = NULL
Browse files Browse the repository at this point in the history
  • Loading branch information
hfrick committed May 22, 2024
1 parent c82c2a2 commit a195811
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

* `vfold_cv()` now utilizes the `breaks` argument correctly for repeated cross-validation (@ZWael, #471).

* Grouped resampling functions now work with an explicit `strata = NULL` instead of strata being either a name or missing (#485).

## Breaking changes

* The class of grouped MC splits is now `group_mc_split` instead of `grouped_mc_split`, aligning it with the other grouped splits (#478).
Expand Down
6 changes: 6 additions & 0 deletions R/vfold.R
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,12 @@ check_v <- function(v, max_v, rows = "rows", call = rlang::caller_env()) {
check_grouped_strata <- function(group, strata, pool, data) {

strata <- tidyselect::vars_select(names(data), !!enquo(strata))

# if strata was NULL this is empty, thus return NULL
if (length(strata) < 1) {
return(NULL)
}

grouped_table <- tibble(
group = getElement(data, group),
strata = getElement(data, strata)
Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/test-vfold.R
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,18 @@ test_that("grouping -- default param", {
expect_true(all(table(sp_out) == 1))
})

test_that("grouping works with non-missing strata = NULL", {
set.seed(11)
rset_strata_missing <- group_vfold_cv(warpbreaks, "tension")

expect_no_error({
set.seed(11)
rset_strata_null <- group_vfold_cv(warpbreaks, "tension", strata = NULL)
})

expect_identical(rset_strata_null, rset_strata_missing)

})

test_that("grouping -- v < max v", {
set.seed(11)
Expand Down

0 comments on commit a195811

Please sign in to comment.