Skip to content

Commit

Permalink
correct argument checking
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpcouch committed Jul 29, 2024
1 parent 056f116 commit 109ab48
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,14 @@ check_numeric <- function(x, arg = caller_arg(x), call = caller_env()) {
}
}

check_integer <- function(x, arg = caller_arg(x), call = caller_env()) {
if (!inherits(x, "integer")) {
cli::cli_abort("{.arg {arg}} must be an integer.", call = call)
}
}

check_outcome <- function(x, arg = caller_arg(x), call = caller_env()) {
if (!inherits_any(x, c("integer", "factor"))) {
cli::cli_abort("{.arg {arg}} must be an integer.", call = call)
cli::cli_abort("{.arg {arg}} must be an integer or factor.", call = call)
}
}
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
check_y(rnorm(10), "classification")
Condition
Error:
! `y` must be an integer.
! `y` must be an integer or factor.

---

Expand Down

0 comments on commit 109ab48

Please sign in to comment.