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

Keep attributes up to parity with rsample #94

Merged
merged 5 commits into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
16 changes: 13 additions & 3 deletions R/spatial_vfold_cv.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/_snaps/spatial_vfold_cv.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

---
Expand All @@ -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.

---
Expand Down