From 28693ac520a8b59e35fa99b190ef3e33bee3d5d6 Mon Sep 17 00:00:00 2001 From: David Hugh-Jones Date: Mon, 10 Jun 2024 09:59:53 +0100 Subject: [PATCH] Make `close_end` implicit in `...` in `chop_n()`, `chop_equally()` and `chop_evenly()`. The default has changed to `close_end = TRUE` anyway. --- R/chop-by-group-size.R | 13 +++++-------- R/chop-by-width.R | 7 ++----- man/chop_equally.Rd | 8 +++----- man/chop_evenly.Rd | 8 +------- man/chop_n.Rd | 5 +---- 5 files changed, 12 insertions(+), 29 deletions(-) diff --git a/R/chop-by-group-size.R b/R/chop-by-group-size.R index 232aec1..da1875f 100644 --- a/R/chop-by-group-size.R +++ b/R/chop-by-group-size.R @@ -90,8 +90,6 @@ chop_deciles <- function(x, ...) { #' elements, you may get fewer `groups` than requested. If so, a warning will #' be emitted. See the examples. #' -#' -#' #' @family chopping functions #' #' @export @@ -99,21 +97,21 @@ chop_deciles <- function(x, ...) { #' @examples #' chop_equally(1:10, 5) #' -#' # You can't always guarantee `groups` groups: +#' # You can't always guarantee equal-sized groups: #' dupes <- c(1, 1, 1, 2, 3, 4, 4, 4) #' quantile(dupes, 0:4/4) #' chop_equally(dupes, 4) +#' # Or as many groups as you ask for: +#' chop_equally(c(1, 1, 2, 2), 3) chop_equally <- function ( x, groups, ..., labels = lbl_intervals(), left = is.numeric(x), - close_end = TRUE, raw = TRUE ) { - chop(x, brk_equally(groups), ..., labels = labels, left = left, - close_end = close_end, raw = raw) + chop(x, brk_equally(groups), ..., labels = labels, left = left, raw = raw) } @@ -159,10 +157,9 @@ chop_n <- function ( x, n, ..., - close_end = TRUE, tail = "split" ) { - res <- chop(x, brk_n(n, tail = tail), ..., close_end = close_end) + res <- chop(x, brk_n(n, tail = tail), ...) if (tail == "split" && max(tabulate(res)) > n) { warning("Some intervals contain more than ", n, " elements") } diff --git a/R/chop-by-width.R b/R/chop-by-width.R index 88c6bd1..61b2452 100644 --- a/R/chop-by-width.R +++ b/R/chop-by-width.R @@ -47,8 +47,6 @@ chop_width <- function ( #' @inheritParams chop #' @inherit chop-doc params return #' -#' @details `chop_evenly()` sets `close_end = TRUE` by default. -#' #' @family chopping functions #' #' @export @@ -59,10 +57,9 @@ chop_width <- function ( chop_evenly <- function ( x, intervals, - ..., - close_end = TRUE + ... ) { - chop(x, brk_evenly(intervals), ..., close_end = close_end) + chop(x, brk_evenly(intervals), ...) } diff --git a/man/chop_equally.Rd b/man/chop_equally.Rd index 2d3e1a5..92c1f60 100644 --- a/man/chop_equally.Rd +++ b/man/chop_equally.Rd @@ -13,7 +13,6 @@ chop_equally( ..., labels = lbl_intervals(), left = is.numeric(x), - close_end = TRUE, raw = TRUE ) @@ -32,9 +31,6 @@ tab_equally(x, groups, ..., left = is.numeric(x), raw = TRUE) \item{left}{Logical. Left-closed or right-closed breaks?} -\item{close_end}{Logical. Close last break at right? (If \code{left} is \code{FALSE}, -close first break at left?)} - \item{raw}{Logical. Use raw values in labels?} } \value{ @@ -55,10 +51,12 @@ be emitted. See the examples. \examples{ chop_equally(1:10, 5) -# You can't always guarantee `groups` groups: +# You can't always guarantee equal-sized groups: dupes <- c(1, 1, 1, 2, 3, 4, 4, 4) quantile(dupes, 0:4/4) chop_equally(dupes, 4) +# Or as many groups as you ask for: +chop_equally(c(1, 1, 2, 2), 3) } \seealso{ Other chopping functions: diff --git a/man/chop_evenly.Rd b/man/chop_evenly.Rd index 5b799ef..3133a89 100644 --- a/man/chop_evenly.Rd +++ b/man/chop_evenly.Rd @@ -6,7 +6,7 @@ \alias{tab_evenly} \title{Chop into equal-width intervals} \usage{ -chop_evenly(x, intervals, ..., close_end = TRUE) +chop_evenly(x, intervals, ...) brk_evenly(intervals) @@ -18,9 +18,6 @@ tab_evenly(x, intervals, ...) \item{intervals}{Integer: number of intervals to create.} \item{...}{Passed to \code{\link[=chop]{chop()}}.} - -\item{close_end}{Logical. Close last break at right? (If \code{left} is \code{FALSE}, -close first break at left?)} } \value{ \verb{chop_*} functions return a \code{\link{factor}} of the same length as \code{x}. @@ -32,9 +29,6 @@ close first break at left?)} \description{ \code{chop_evenly()} chops \code{x} into \code{intervals} intervals of equal width. } -\details{ -\code{chop_evenly()} sets \code{close_end = TRUE} by default. -} \examples{ chop_evenly(0:10, 5) diff --git a/man/chop_n.Rd b/man/chop_n.Rd index 341cd15..8eaafb3 100644 --- a/man/chop_n.Rd +++ b/man/chop_n.Rd @@ -7,7 +7,7 @@ \alias{tab_n} \title{Chop into fixed-sized groups} \usage{ -chop_n(x, n, ..., close_end = TRUE, tail = "split") +chop_n(x, n, ..., tail = "split") brk_n(n, tail = "split") @@ -20,9 +20,6 @@ tab_n(x, n, ..., tail = "split") \item{...}{Passed to \code{\link[=chop]{chop()}}.} -\item{close_end}{Logical. Close last break at right? (If \code{left} is \code{FALSE}, -close first break at left?)} - \item{tail}{String. What to do if the final interval has fewer than \code{n} elements? \code{"split"} to keep it separate. \code{"merge"} to merge it with the neighbouring interval.}