Skip to content

Commit

Permalink
correct misleading error (#6043)
Browse files Browse the repository at this point in the history
  • Loading branch information
catalamarti committed Aug 15, 2024
1 parent 11244c5 commit 19d4550
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions R/utilities-break.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
#' table(cut_width(runif(1000), 0.1, center = 0))
#' table(cut_width(runif(1000), 0.1, labels = FALSE))
cut_interval <- function(x, n = NULL, length = NULL, ...) {
if ((!is.null(n) && !is.null(length)) || (is.null(n) && is.null(length))) {
cli::cli_abort("Specify exactly one of {.var n} and {.var length}.")
}
cut(x, breaks(x, "width", n, length), include.lowest = TRUE, ...)
}

Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/_snaps/utilities-break.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# cut_interval gives the correct

Specify exactly one of `n` and `length`.

3 changes: 3 additions & 0 deletions tests/testthat/test-utilities-break.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test_that("cut_interval throws the correct error message", {
expect_snapshot_error(cut_interval(x = 1:10, width = 10))
})

0 comments on commit 19d4550

Please sign in to comment.