Skip to content

Commit

Permalink
fix range param assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
pat-s committed Mar 18, 2021
1 parent bcc960d commit 9626467
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion R/ResamplingSpCVBlock.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#' task = tsk("ecuador")
#'
#' # Instantiate Resampling
#' rcv = rsmp("spcv_block", range = 1000)
#' rcv = rsmp("spcv_block", range = 1000L)
#' rcv$instantiate(task)
#'
#' # Individual sets:
Expand Down
2 changes: 1 addition & 1 deletion R/autoplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
#' library(mlr3)
#' library(mlr3spatiotempcv)
#' task = tsk("ecuador")
#' resampling = rsmp("spcv_block", range = 1000)
#' resampling = rsmp("spcv_block", range = 1000L)
#' resampling$instantiate(task)
#'
#' ## Visualize all partitions
Expand Down
2 changes: 1 addition & 1 deletion man/ResamplingSpCVBlock.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/autoplot.ResamplingSpCVBlock.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testthat/test-1-autoplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ test_that("plot() works for 'repeated_spcv_block'", {
set.seed(42)

plots = prepare_autoplot("repeated_spcv_block",
folds = 4, range = c(2, 4), repeats = 2)
folds = 4, range = c(2L, 4L), repeats = 2)

# autoplot() is used instead of plot() to prevent side-effect plotting
p1 = autoplot(plots$rsp, plots$task, crs = 4326)
Expand Down
12 changes: 6 additions & 6 deletions tests/testthat/test-ResamplingRepeatedSpCVBlock.R
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
test_that("folds can be printed", {
task = test_make_twoclass_task()
rsp = rsmp("repeated_spcv_block", folds = 3, repeats = 2, range = c(2, 4))
rsp = rsmp("repeated_spcv_block", folds = 3, repeats = 2, range = c(2L, 4L))
rsp$instantiate(task)

expect_equal(rsp$folds(1:6), c(1, 2, 1, 2, 1, 2))
})

test_that("reps can be printed", {
task = test_make_twoclass_task()
rsp = rsmp("repeated_spcv_block", folds = 3, repeats = 2, range = c(2, 4))
rsp = rsmp("repeated_spcv_block", folds = 3, repeats = 2, range = c(2L, 4L))
rsp$instantiate(task)

expect_equal(rsp$repeats(1:9), c(1, 1, 1, 2, 2, 2, 3, 3, 3))
})

test_that("resampling iterations equals folds * repeats", {
task = test_make_twoclass_task()
rsp = rsmp("repeated_spcv_block", folds = 3, repeats = 2, range = c(2, 4))
rsp = rsmp("repeated_spcv_block", folds = 3, repeats = 2, range = c(2L, 4L))
rsp$instantiate(task)

expect_equal(rsp$iters, 6)
Expand All @@ -32,7 +32,7 @@ test_that("error when neither cols & rows | range is specified", {

test_that("error when length(range) != length(repeats)", {
task = test_make_twoclass_task()
rsp = rsmp("repeated_spcv_block", repeats = 2, range = 5)
rsp = rsmp("repeated_spcv_block", repeats = 2, range = 5L)
expect_error(
rsp$instantiate(task),
".*to be the same length as 'range'."
Expand All @@ -41,13 +41,13 @@ test_that("error when length(range) != length(repeats)", {

test_that("no error when length(range) == repeats", {
task = test_make_twoclass_task()
rsp = rsmp("repeated_spcv_block", folds = 3, repeats = 2, range = c(2, 4))
rsp = rsmp("repeated_spcv_block", folds = 3, repeats = 2, range = c(2L, 4L))
expect_silent(rsp$instantiate(task))
})

test_that("error when number of desired folds is larger than number possible blocks", {
task = test_make_twoclass_task()
rsp = rsmp("repeated_spcv_block", folds = 10, repeats = 2, range = c(2, 4))
rsp = rsmp("repeated_spcv_block", folds = 10, repeats = 2, range = c(2L, 4L))
expect_error(rsp$instantiate(task))
})

Expand Down
14 changes: 7 additions & 7 deletions tests/testthat/test-ResamplingSpCVBlock.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
test_that("resampling iterations equals folds", {
task = test_make_twoclass_task()
rsp = rsmp("spcv_block", folds = 2, range = 2)
rsp = rsmp("spcv_block", folds = 2, range = 2L)
rsp$instantiate(task)

expect_equal(rsp$iters, 2)
})

test_that("error when number of desired folds is larger than number possible blocks", {
task = test_make_twoclass_task()
rsp = rsmp("spcv_block", folds = 10, range = 4)
rsp = rsmp("spcv_block", folds = 10, range = 4L)

expect_error(rsp$instantiate(task))
})
Expand All @@ -33,7 +33,7 @@ test_that("error when only one of rows or cols is set", {
})

test_that("Error when length(range) >= 2", {
expect_error(rsmp("spcv_block", range = c(500, 1000)))
expect_error(rsmp("spcv_block", range = c(500L, 1000L)))
})


Expand All @@ -44,7 +44,7 @@ test_that("mlr3spatiotempcv indices are the same as blockCV indices: selection =
task = test_make_blockCV_test_task()

rsmp <- rsmp("spcv_block",
range = 50000,
range = 50000L,
selection = "checkerboard")
rsmp$instantiate(task)

Expand All @@ -53,7 +53,7 @@ test_that("mlr3spatiotempcv indices are the same as blockCV indices: selection =
capture.output(testBlock <- suppressMessages(
suppressWarnings(blockCV::spatialBlock(
speciesData = testSF,
theRange = 50000,
theRange = 50000L,
selection = "checkerboard",
showBlocks = FALSE)
)))
Expand Down Expand Up @@ -98,7 +98,7 @@ test_that("mlr3spatiotempcv indices are the same as blockCV indices: rasterLayer
r[] <- 10

rsmp <- rsmp("spcv_block",
range = 50000,
range = 50000L,
selection = "checkerboard",
rasterLayer = r)
rsmp$instantiate(task)
Expand All @@ -108,7 +108,7 @@ test_that("mlr3spatiotempcv indices are the same as blockCV indices: rasterLayer
capture.output(testBlock <- suppressMessages(
blockCV::spatialBlock(
speciesData = testSF,
theRange = 50000,
theRange = 50000L,
selection = "checkerboard",
rasterLayer = r,
showBlocks = FALSE,
Expand Down

0 comments on commit 9626467

Please sign in to comment.