From 4902715f1e97ef3593454618f342d46584369a34 Mon Sep 17 00:00:00 2001 From: David Hugh-Jones Date: Tue, 11 Jun 2024 17:04:14 +0100 Subject: [PATCH] Small tweaks --- R/breaks-by-group-size.R | 2 +- R/breaks.R | 7 ++++++- R/chop-isolates.R | 6 +++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/R/breaks-by-group-size.R b/R/breaks-by-group-size.R index f17e24a..7808852 100644 --- a/R/breaks-by-group-size.R +++ b/R/breaks-by-group-size.R @@ -32,7 +32,7 @@ brk_quantiles <- function (probs, ..., weights = NULL, recalc_probs = FALSE) { if (anyNA(qs)) return(empty_breaks()) # data was all NA - if (any(duplicated(qs))) { + if (anyDuplicated(qs) > 0L) { if (! recalc_probs) { warning("`x` has duplicate quantiles: break labels may be misleading") } diff --git a/R/breaks.R b/R/breaks.R index ccc523d..808508f 100644 --- a/R/breaks.R +++ b/R/breaks.R @@ -31,8 +31,13 @@ brk_spikes <- function (breaks, n = NULL, prop = NULL) { assert_that( is.number(n) || is.number(prop), is.null(n) || is.null(prop), - msg = "exactly one of `n` and `prop` must be specified as a scalar numeric" + msg = "exactly one of `n` and `prop` must be a scalar numeric" ) + assert_that( + # it's ok for one of these to be null + n >= 0 || prop >= 0 + ) + if (! is.function(breaks)) breaks <- brk_default(breaks) function (x, extend, left, close_end) { diff --git a/R/chop-isolates.R b/R/chop-isolates.R index cbf8ad2..eb28f41 100644 --- a/R/chop-isolates.R +++ b/R/chop-isolates.R @@ -101,7 +101,11 @@ dissect <- function (x, assert_that( is.number(n) || is.number(prop), is.null(n) || is.null(prop), - msg = "exactly one of `n` and `prop` must be specified as a scalar numeric" + msg = "exactly one of `n` and `prop` must be a scalar numeric" + ) + assert_that( + # it's ok for one of these to be null + n >= 0 || prop >= 0 ) chopped <- chop(x, breaks, ...)