Skip to content

Commit 325aef2

Browse files
Warn too many breaks before doing seq() (#4132)
1 parent dcad61a commit 325aef2

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

R/bin.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,16 @@ bin_breaks_width <- function(x_range, width = NULL, center = NULL,
8585
# Small correction factor so that we don't get an extra bin when, for
8686
# example, origin = 0, max(x) = 20, width = 10.
8787
max_x <- x_range[2] + (1 - 1e-08) * width
88+
89+
if (isTRUE((max_x - origin) / width > 1e6)) {
90+
abort("The number of histogram bins must be less than 1,000,000.\nDid you make `binwidth` too small?")
91+
}
8892
breaks <- seq(origin, max_x, width)
8993

9094
if (length(breaks) == 1) {
9195
# In exceptionally rare cases, the above can fail and produce only a
9296
# single break (see issue #3606). We fix this by adding a second break.
9397
breaks <- c(breaks, breaks + width)
94-
} else if (length(breaks) > 1e6) {
95-
abort("The number of histogram bins must be less than 1,000,000.\nDid you make `binwidth` too small?")
9698
}
9799

98100
bin_breaks(breaks, closed = closed)

0 commit comments

Comments
 (0)