Skip to content

Commit 05f519b

Browse files
authored
breaks_pretty() will return zero-range limit (#455)
1 parent 5a3ddee commit 05f519b

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

NEWS.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# scales (development version)
22

3+
* `breaks_pretty()` will return the input limit when it has no range (#446)
34
* `transform_exp()` now has more sensible breaks, available in `breaks_exp()`
45
(@teunbrand, #405).
56
* The scales package now keeps track of known palettes. These can be retrieved

R/breaks.R

+3
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ breaks_pretty <- function(n = 5, ...) {
122122
force_all(n, ...)
123123
n_default <- n
124124
function(x, n = n_default) {
125+
if (zero_range(as.numeric(x))) {
126+
return(x[1])
127+
}
125128
breaks <- pretty(x, n, ...)
126129
names(breaks) <- attr(breaks, "labels")
127130
breaks

tests/testthat/test-breaks.R

+4-1
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@ test_that("breaks_pretty() arguments are forcely evaluated on each call #81", {
3131
expect_equal(subfun2(1), subfuns[[2]](1))
3232
})
3333

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

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

0 commit comments

Comments
 (0)