Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
})
Loading