Skip to content

Commit

Permalink
breaks_pretty() will return zero-range limit (#455)
Browse files Browse the repository at this point in the history
  • Loading branch information
teunbrand authored Oct 21, 2024
1 parent 5a3ddee commit 05f519b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# scales (development version)

* `breaks_pretty()` will return the input limit when it has no range (#446)
* `transform_exp()` now has more sensible breaks, available in `breaks_exp()`
(@teunbrand, #405).
* The scales package now keeps track of known palettes. These can be retrieved
Expand Down
3 changes: 3 additions & 0 deletions R/breaks.R
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ breaks_pretty <- function(n = 5, ...) {
force_all(n, ...)
n_default <- n
function(x, n = n_default) {
if (zero_range(as.numeric(x))) {
return(x[1])
}
breaks <- pretty(x, n, ...)
names(breaks) <- attr(breaks, "labels")
breaks
Expand Down
5 changes: 4 additions & 1 deletion tests/testthat/test-breaks.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ test_that("breaks_pretty() arguments are forcely evaluated on each call #81", {
expect_equal(subfun2(1), subfuns[[2]](1))
})

test_that("exponential breaks give sensible values", {
test_that("breaks_pretty() returns input when given zero-width range (#446)", {
expect_equal(breaks_pretty()(c(1, 1)), 1)
})

test_that("exponential breaks give sensible values", {
x <- breaks_exp()(c(0, 2))
expect_equal(x, c(0, 0.5, 1, 1.5, 2))

Expand Down

0 comments on commit 05f519b

Please sign in to comment.