diff --git a/NEWS.md b/NEWS.md index ea34a0d..ba9f344 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,11 @@ # spatialsample (development version) +* `spatial_buffer_vfold_cv()` has had some attribute changes to match `rsample`: + * `strata` attribute is now the name of the column used for stratification, + or not set if there was no stratification. + * `pool` and `breaks` have been added as attributes + * `radius` and `buffer` are now set to 0 if they were passed as `NULL`. + # spatialsample 0.2.0 ## New features diff --git a/R/spatial_vfold_cv.R b/R/spatial_vfold_cv.R index 11329d6..8528b0e 100644 --- a/R/spatial_vfold_cv.R +++ b/R/spatial_vfold_cv.R @@ -99,11 +99,21 @@ spatial_buffer_vfold_cv <- function(data, ... ) + if (!missing(strata)) { + strata <- tidyselect::vars_select(names(data), {{ strata }}) + if (length(strata) == 0) strata <- NULL + } + + if (!is.null(strata)) names(strata) <- NULL cv_att <- list(v = v, repeats = repeats, - strata = !is.null(strata), - radius = radius, - buffer = buffer) + strata = strata, + breaks = breaks, + pool = pool, + # Set radius and buffer to 0 if NULL or negative + # This enables rsample::reshuffle_rset to work + radius = min(c(radius, 0)), + buffer = min(c(buffer, 0))) if ("sf" %in% class(data)) { rset_class <- c("spatial_buffer_vfold_cv", "spatial_rset", "rset") diff --git a/tests/testthat/_snaps/spatial_vfold_cv.md b/tests/testthat/_snaps/spatial_vfold_cv.md index 6f9bfa2..2f9dede 100644 --- a/tests/testthat/_snaps/spatial_vfold_cv.md +++ b/tests/testthat/_snaps/spatial_vfold_cv.md @@ -60,7 +60,7 @@ Code spatial_leave_location_out_cv(ames) Condition - Error: + Error in `rsample::group_vfold_cv()`: ! `group` should be a single character value for the column that will be used for splitting. --- @@ -77,7 +77,7 @@ Code spatial_leave_location_out_cv(ames_sf, v = c(5, 10)) Condition - Error: + Error in `rsample::group_vfold_cv()`: ! `group` should be a single character value for the column that will be used for splitting. ---