11bins <- function (breaks , closed = " right" ,
22 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 )
64 closed <- arg_match0(closed , c(" right" , " left" ))
75
86 breaks <- sort(breaks )
@@ -56,12 +54,7 @@ bin_breaks_width <- function(x_range, width = NULL, center = NULL,
5654 cli :: cli_abort(" {.arg x_range} must have two elements" )
5755 }
5856
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 )
6558 if (width < = 0 ) {
6659 cli :: cli_abort(" {.arg binwidth} must be positive" )
6760 }
@@ -115,10 +108,8 @@ bin_breaks_bins <- function(x_range, bins = 30, center = NULL,
115108 cli :: cli_abort(" {.arg x_range} must have two elements" )
116109 }
117110
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 )) {
122113 # 0.1 is the same width as the expansion `default_expansion()` gives for 0-width data
123114 width <- 0.1
124115 } else if (bins == 1 ) {
@@ -136,9 +127,7 @@ bin_breaks_bins <- function(x_range, bins = 30, center = NULL,
136127# Compute bins ------------------------------------------------------------
137128
138129bin_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" )
142131
143132 if (all(is.na(x ))) {
144133 return (bin_out(length(x ), NA , NA , xmin = NA , xmax = NA ))
0 commit comments