Skip to content

Prevent failure of binning algorithm in rare cases. #3613

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 6, 2019
Merged
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
6 changes: 5 additions & 1 deletion R/bin.R
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ bin_breaks_width <- function(x_range, width = NULL, center = NULL,
max_x <- x_range[2] + (1 - 1e-08) * width
breaks <- seq(origin, max_x, width)

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

Expand Down