Skip to content

Commit 15241a6

Browse files
committed
inline find_origin()
1 parent 2ce92fb commit 15241a6

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

R/utilities-break.R

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ cut_width <- function(x, width, center = NULL, boundary = NULL, closed = "right"
7676
}
7777
boundary <- as.numeric(boundary)
7878

79-
# Determine bins
80-
min_x <- find_origin(x_range, width, boundary)
79+
# Determine bins, find origin
80+
min_x <- boundary + floor((x_range[1] - boundary) / width) * width
8181
# Small correction factor so that we don't get an extra bin when, for
8282
# example, origin = 0, max(x) = 20, width = 10.
8383
max_x <- max(x, na.rm = TRUE) + (1 - 1e-08) * width
@@ -86,12 +86,6 @@ cut_width <- function(x, width, center = NULL, boundary = NULL, closed = "right"
8686
cut(x, breaks, include.lowest = TRUE, right = (closed == "right"), ...)
8787
}
8888

89-
# Find the left side of left-most bin
90-
find_origin <- function(x_range, width, boundary) {
91-
shift <- floor((x_range[1] - boundary) / width)
92-
boundary + shift * width
93-
}
94-
9589
breaks <- function(x, equal, nbins = NULL, binwidth = NULL) {
9690
equal <- arg_match0(equal, c("numbers", "width"))
9791
if ((!is.null(nbins) && !is.null(binwidth)) || (is.null(nbins) && is.null(binwidth))) {

0 commit comments

Comments
 (0)