1
1
bins <- function (breaks , closed = " right" ,
2
2
fuzz = 1e-08 * stats :: median(diff(breaks ))) {
3
- if (! is.numeric(breaks )) {
4
- cli :: cli_abort(" {.arg breaks} must be a numeric vector" )
5
- }
3
+ check_numeric(breaks )
6
4
closed <- arg_match0(closed , c(" right" , " left" ))
7
5
8
6
breaks <- sort(breaks )
@@ -56,12 +54,7 @@ bin_breaks_width <- function(x_range, width = NULL, center = NULL,
56
54
cli :: cli_abort(" {.arg x_range} must have two elements" )
57
55
}
58
56
59
- # if (length(x_range) == 0) {
60
- # return(bin_params(numeric()))
61
- # }
62
- if (! (is.numeric(width ) && length(width ) == 1 )) {
63
- cli :: cli_abort(" {.arg width} must be a number" )
64
- }
57
+ check_number_decimal(width )
65
58
if (width < = 0 ) {
66
59
cli :: cli_abort(" {.arg binwidth} must be positive" )
67
60
}
@@ -115,10 +108,8 @@ bin_breaks_bins <- function(x_range, bins = 30, center = NULL,
115
108
cli :: cli_abort(" {.arg x_range} must have two elements" )
116
109
}
117
110
118
- bins <- as.integer(bins )
119
- if (bins < 1 ) {
120
- cli :: cli_abort(" {.arg bins} must be 1 or greater" )
121
- } else if (zero_range(x_range )) {
111
+ check_number_whole(bins , min = 1 )
112
+ if (zero_range(x_range )) {
122
113
# 0.1 is the same width as the expansion `default_expansion()` gives for 0-width data
123
114
width <- 0.1
124
115
} else if (bins == 1 ) {
@@ -136,9 +127,7 @@ bin_breaks_bins <- function(x_range, bins = 30, center = NULL,
136
127
# Compute bins ------------------------------------------------------------
137
128
138
129
bin_vector <- function (x , bins , weight = NULL , pad = FALSE ) {
139
- if (! is_bins(bins )) {
140
- cli :: cli_abort(" {.arg bins} must be a {.cls ggplot2_bins} object" )
141
- }
130
+ check_object(bins , is_bins , " a {.cls ggplot2_bins} object" )
142
131
143
132
if (all(is.na(x ))) {
144
133
return (bin_out(length(x ), NA , NA , xmin = NA , xmax = NA ))
0 commit comments