From 0a78c90d0558757b37d6a80bcb13abc34baf79e3 Mon Sep 17 00:00:00 2001 From: Claus Wilke Date: Tue, 5 Nov 2019 00:14:07 -0600 Subject: [PATCH] fixes #3606 --- R/bin.R | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/R/bin.R b/R/bin.R index 55d898c846..cea2f1faa6 100644 --- a/R/bin.R +++ b/R/bin.R @@ -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) }