Skip to content
Open
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
40 changes: 24 additions & 16 deletions R/spatial_vfold_cv.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,26 +88,34 @@ spatial_buffer_vfold_cv <- function(data,

n <- nrow(data)
v <- check_v(v, n, "rows")
if (v == n && repeats > 1) {
rlang::abort(
c(
"Repeated cross-validation doesn't make sense when performing leave-one-out cross-validation.",
i = "Set `v` to a lower value.",
i = "Or set `repeats = 1`."

if (v == n) {
if (repeats > 1) {
rlang::abort(
c(
"Repeated cross-validation doesn't make sense when performing leave-one-out cross-validation.",
i = "Set `v` to a lower value.",
i = "Or set `repeats = 1`."
)
)
}
rset <- rsample::loo_cv(data)

# change `id` to match vfold style
# no need to change the rset class here since we're setting it at the end
rset$id <- names0(length(rset$splits), "Fold")
} else {
rset <- rsample::vfold_cv(
data = data,
v = v,
repeats = repeats,
strata = {{ strata }},
breaks = breaks,
pool = pool,
...
)
}

rset <- rsample::vfold_cv(
data = data,
v = v,
repeats = repeats,
strata = {{ strata }},
breaks = breaks,
pool = pool,
...
)

if (!missing(strata)) {
strata <- tidyselect::vars_select(names(data), {{ strata }})
if (length(strata) == 0) strata <- NULL
Expand Down
20 changes: 10 additions & 10 deletions tests/testthat/_snaps/autoplot/block-plots-with-grid.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions tests/testthat/_snaps/autoplot/buffered-rsample-plot.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 20 additions & 20 deletions tests/testthat/_snaps/autoplot/buffered-rset-plot.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading