Skip to content

Commit

Permalink
verify that the 'metrics' argument is a metric set (#817)
Browse files Browse the repository at this point in the history
* verify that the 'metrics' argument is a metric set for #813 and #812

* Update R/int_pctl.R

Co-authored-by: Hannah Frick <[email protected]>

* update snapshot

---------

Co-authored-by: Hannah Frick <[email protected]>
  • Loading branch information
topepo and hfrick authored Jan 19, 2024
1 parent 4cd4646 commit ff29ea0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions R/int_pctl.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ int_pctl.tune_results <- function(.data, metrics = NULL, times = 1001,

if (is.null(metrics)) {
metrics <- .get_tune_metrics(.data)
} else {
if (!inherits(metrics, "metric_set")) {
cli::cli_abort("{.arg metrics} should be a metric set as generated by {.fun yardstick::metric_set}.")
}
}

res <-
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/_snaps/int_pctl.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
Warning:
Recommend at least 1000 non-missing bootstrap resamples for terms: `rmse`, `rsq`.

---

Code
int_pctl(lm_res, times = 2000, metrics = "rmse")
Condition
Error in `int_pctl()`:
! `metrics` should be a metric set as generated by `yardstick::metric_set()`.

# percentile intervals - last fit

Code
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/test-int_pctl.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ test_that("percentile intervals - resamples only", {
expect_equal(int_res_1[0,], template)
expect_equal(nrow(int_res_1), 2)

expect_snapshot(int_pctl(lm_res, times = 2000, metrics = "rmse"), error = TRUE)

})


Expand Down

0 comments on commit ff29ea0

Please sign in to comment.