Skip to content

Commit 19d4550

Browse files
authored
correct misleading error (#6043)
1 parent 11244c5 commit 19d4550

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

R/utilities-break.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
#' table(cut_width(runif(1000), 0.1, center = 0))
2525
#' table(cut_width(runif(1000), 0.1, labels = FALSE))
2626
cut_interval <- function(x, n = NULL, length = NULL, ...) {
27+
if ((!is.null(n) && !is.null(length)) || (is.null(n) && is.null(length))) {
28+
cli::cli_abort("Specify exactly one of {.var n} and {.var length}.")
29+
}
2730
cut(x, breaks(x, "width", n, length), include.lowest = TRUE, ...)
2831
}
2932

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# cut_interval gives the correct
2+
3+
Specify exactly one of `n` and `length`.
4+

tests/testthat/test-utilities-break.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
test_that("cut_interval throws the correct error message", {
2+
expect_snapshot_error(cut_interval(x = 1:10, width = 10))
3+
})

0 commit comments

Comments
 (0)