Skip to content

Commit

Permalink
pass calls and test aborts in grids.R
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilHvitfeldt committed Sep 20, 2024
1 parent ba5a698 commit 0f5f2df
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
6 changes: 3 additions & 3 deletions R/grids.R
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ make_regular_grid <- function(...,
parameters <- dplyr::filter(parameters, !!filter_quo)
}

new_param_grid(parameters)
new_param_grid(parameters, call = call)
}

# ------------------------------------------------------------------------------
Expand Down Expand Up @@ -246,12 +246,12 @@ make_random_grid <- function(...,
parameters <- dplyr::filter(parameters, !!filter_quo)
}

new_param_grid(parameters)
new_param_grid(parameters, call = call)
}

# ------------------------------------------------------------------------------

new_param_grid <- function(x = new_data_frame()) {
new_param_grid <- function(x = new_data_frame(), call = caller_env()) {
if (!is.data.frame(x)) {
cli::cli_abort(
"{.arg x} must be a data frame to construct a new grid from."
Expand Down
2 changes: 1 addition & 1 deletion R/space_filling.R
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ make_sfd <- function(...,
)
}

new_param_grid(grid)
new_param_grid(grid, call = call)
}

base_recycle <- function(x, size) {
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/_snaps/grids.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@
Error in `parameters()`:
! The objects should all be <param> objects.

---

Code
grid_regular(mixture(), trees(), levels = c(2, trees = 4))
Condition
Error in `grid_regular()`:
! Elements of `levels` should either be all named or unnamed, not mixed.

# wrong argument name

Code
Expand Down
5 changes: 5 additions & 0 deletions tests/testthat/test-grids.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ test_that("regular grid", {
grid_regular(list(mixture(), trees()), levels = 3),
grid_regular(mixture(), trees(), levels = 3)
)

expect_snapshot(
error = TRUE,
grid_regular(mixture(), trees(), levels = c(2, trees = 4))
)
})

test_that("random grid", {
Expand Down

0 comments on commit 0f5f2df

Please sign in to comment.