Skip to content

Commit

Permalink
Add expand_bbox attribute (Fixes #153) (#154)
Browse files Browse the repository at this point in the history
* Add expand_bbox attribute

* Update snaps
  • Loading branch information
mikemahoney218 authored Nov 3, 2023
1 parent 3d9dd19 commit bb4f543
Show file tree
Hide file tree
Showing 8 changed files with 4,420 additions and 3,544 deletions.
8 changes: 3 additions & 5 deletions R/autoplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,9 @@ autoplot.spatial_block_cv <- function(object, show_grid = TRUE, ..., alpha = 0.6
data <- object$splits[[1]]$data

plot_data <- data
if (is_longlat(data)) {
plot_data <- sf::st_bbox(data)
plot_data <- expand_grid(plot_data)
plot_data <- sf::st_as_sfc(plot_data)
}
plot_data <- sf::st_bbox(data)
plot_data <- expand_grid(plot_data, attr(object, "expand_bbox"))
plot_data <- sf::st_as_sfc(plot_data)

grid_args <- list(x = plot_data)
grid_args$cellsize <- attr(object, "cellsize", TRUE)
Expand Down
1 change: 1 addition & 0 deletions R/spatial_block_cv.R
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ spatial_block_cv <- function(data,
radius = radius,
buffer = buffer,
repeats = repeats,
expand_bbox = expand_bbox,
...
)

Expand Down
1,700 changes: 850 additions & 850 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.
852 changes: 852 additions & 0 deletions tests/testthat/_snaps/autoplot/expand-bbox.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3,340 changes: 1,670 additions & 1,670 deletions tests/testthat/_snaps/autoplot/repeated-block-cv.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,038 changes: 1,019 additions & 1,019 deletions tests/testthat/_snaps/autoplot/snake-flips-rows-the-right-way.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions tests/testthat/test-autoplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,12 @@ test_that("autoplot is stable", {
autoplot(repeat_llo)
)
})

test_that("autoplot respects expand_bbox", {
vdiffr::expect_doppelganger(
"expand_bbox",
autoplot(
spatial_block_cv(boston_canopy, expand_bbox = 0.5, v = 4)
)
)
})
16 changes: 16 additions & 0 deletions tests/testthat/test-spatial_block_cv.R
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,22 @@ test_that("duplicated observations in assessment sets throws an error", {
)
})

test_that("expand_bbox attribute is set", {
skip_if_not_installed("withr")
folds <- withr::with_seed(
123,
spatial_block_cv(boston_canopy, expand_bbox = 0.01)
)
expect_equal(attr(folds, "expand_bbox"), 0.01)
expect_identical(
folds,
withr::with_seed(
123,
rsample::reshuffle_rset(folds)
)
)
})

test_that("bad args", {
skip_if_not(sf::sf_use_s2())
set.seed(123)
Expand Down

0 comments on commit bb4f543

Please sign in to comment.