1
1
bins <- function (breaks , closed = c(" right" , " left" ),
2
2
fuzz = 1e-08 * stats :: median(diff(breaks ))) {
3
- stopifnot( is.numeric(breaks ))
3
+ if ( ! is.numeric(breaks )) abort( " `breaks` must be a numeric vector " )
4
4
closed <- match.arg(closed )
5
5
6
6
breaks <- sort(breaks )
@@ -50,18 +50,18 @@ bin_breaks <- function(breaks, closed = c("right", "left")) {
50
50
51
51
bin_breaks_width <- function (x_range , width = NULL , center = NULL ,
52
52
boundary = NULL , closed = c(" right" , " left" )) {
53
- stopifnot (length(x_range ) == 2 )
53
+ if (length(x_range ) != 2 ) abort( " `x_range` must have two elements " )
54
54
55
55
# if (length(x_range) == 0) {
56
56
# return(bin_params(numeric()))
57
57
# }
58
- stopifnot( is.numeric(width ), length(width ) == 1 )
58
+ if ( ! ( is.numeric(width ) && length(width ) == 1 )) abort( " `width` must be a numeric scalar " )
59
59
if (width < = 0 ) {
60
- stop (" `binwidth` must be positive" , call. = FALSE )
60
+ abort (" `binwidth` must be positive" )
61
61
}
62
62
63
63
if (! is.null(boundary ) && ! is.null(center )) {
64
- stop (" Only one of 'boundary' and 'center' may be specified." )
64
+ abort (" Only one of 'boundary' and 'center' may be specified." )
65
65
} else if (is.null(boundary )) {
66
66
if (is.null(center )) {
67
67
# If neither edge nor center given, compute both using tile layer's
@@ -92,19 +92,19 @@ bin_breaks_width <- function(x_range, width = NULL, center = NULL,
92
92
# single break (see issue #3606). We fix this by adding a second break.
93
93
breaks <- c(breaks , breaks + width )
94
94
} else if (length(breaks ) > 1e6 ) {
95
- stop (" The number of histogram bins must be less than 1,000,000.\n Did you make `binwidth` too small?" , call. = FALSE )
95
+ abort (" The number of histogram bins must be less than 1,000,000.\n Did you make `binwidth` too small?" )
96
96
}
97
97
98
98
bin_breaks(breaks , closed = closed )
99
99
}
100
100
101
101
bin_breaks_bins <- function (x_range , bins = 30 , center = NULL ,
102
102
boundary = NULL , closed = c(" right" , " left" )) {
103
- stopifnot (length(x_range ) == 2 )
103
+ if (length(x_range ) != 2 ) abort( " `x_range` must have two elements " )
104
104
105
105
bins <- as.integer(bins )
106
106
if (bins < 1 ) {
107
- stop (" Need at least one bin." , call. = FALSE )
107
+ abort (" Need at least one bin." )
108
108
} else if (zero_range(x_range )) {
109
109
# 0.1 is the same width as the expansion `default_expansion()` gives for 0-width data
110
110
width <- 0.1
@@ -123,7 +123,7 @@ bin_breaks_bins <- function(x_range, bins = 30, center = NULL,
123
123
# Compute bins ------------------------------------------------------------
124
124
125
125
bin_vector <- function (x , bins , weight = NULL , pad = FALSE ) {
126
- stopifnot( is_bins(bins ))
126
+ if ( ! is_bins(bins )) abort( " `bins` must be a ggplot2_bins object " )
127
127
128
128
if (all(is.na(x ))) {
129
129
return (bin_out(length(x ), NA , NA , xmin = NA , xmax = NA ))
0 commit comments