Skip to content

Commit

Permalink
Hard-deprecate lbl_endpoint() and lbl_manual(). Use `deprecate_wa…
Browse files Browse the repository at this point in the history
…rn()` for `raw` in `lbl_*` functions.
  • Loading branch information
hughjonesd committed Jun 4, 2024
1 parent 7da11a2 commit d371f47
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 61 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: santoku
Type: Package
Title: A Versatile Cutting Tool
Version: 0.10.0.9000
Version: 1.0.0
Authors@R:
c(
person(given = "David",
Expand Down
6 changes: 5 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
# santoku (development version)
# santoku 1.0.0

* santoku is now considered stable.
* `chop_quantiles()` and `brk_quantiles()` gain a new `weights` argument,
letting you chop by weighted quantiles using `Hmisc::wtd.quantile()`.
* `brk_quantiles()` may now return singleton breaks, producing more
accurate results when `x` has duplicate elements.
* Some deprecated functions have been removed, and the `raw` argument to
`lbl_*` functions now always gives a deprecation warning.


# santoku 0.10.0

Expand Down
2 changes: 1 addition & 1 deletion R/breaks.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ brk_equally <- function (groups) {
#' @importFrom lifecycle deprecated
brk_mean_sd <- function (sds = 1:3, sd = deprecated()) {
if (lifecycle::is_present(sd)) {
lifecycle::deprecate_soft(
lifecycle::deprecate_warn(
when = "0.7.0",
what = "brk_mean_sd(sd)",
with = "brk_mean_sd(sds = 'vector of sds')"
Expand Down
1 change: 0 additions & 1 deletion R/chop.R
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,6 @@ chop_mean_sd <- function (
}



#' Chop using pretty breakpoints
#'
#' `chop_pretty()` uses [base::pretty()] to calculate breakpoints
Expand Down
47 changes: 17 additions & 30 deletions R/labels.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ lbl_intervals <- function (
raw = FALSE
) {
if (! isFALSE(raw)) {
lifecycle::deprecate_soft("0.9.0", "lbl_intervals(raw)", "chop(raw)")
lifecycle::deprecate_warn("0.9.0", "lbl_intervals(raw)", "chop(raw)")
}
interval_glue <- "{ifelse(l_closed, '[', '(')}{l}, {r}{ifelse(r_closed, ']', ')')}"
lbl_glue(label = interval_glue, single = single, fmt = fmt, first = first,
Expand Down Expand Up @@ -116,7 +116,7 @@ lbl_dash <- function (
raw = FALSE
) {
if (! isFALSE(raw)) {
lifecycle::deprecate_soft("0.9.0", "lbl_dash(raw)", "chop(raw)")
lifecycle::deprecate_warn("0.9.0", "lbl_dash(raw)", "chop(raw)")
}

label_glue <- paste0("{l}", symbol, "{r}")
Expand Down Expand Up @@ -147,7 +147,7 @@ lbl_midpoints <- function (
raw = FALSE
) {
if (! isFALSE(raw)) {
lifecycle::deprecate_soft("0.9.0", "lbl_midpoints(raw)", "chop(raw)")
lifecycle::deprecate_warn("0.9.0", "lbl_midpoints(raw)", "chop(raw)")
}

RAW <- raw # avoid "recursive default argument reference"
Expand Down Expand Up @@ -229,7 +229,7 @@ lbl_glue <- function (
)

if (! isFALSE(raw)) {
lifecycle::deprecate_soft("0.9.0", "lbl_glue(raw)", "chop(raw)")
lifecycle::deprecate_warn("0.9.0", "lbl_glue(raw)", "chop(raw)")
}

RAW <- raw # avoid "recursive default argument reference"
Expand Down Expand Up @@ -314,7 +314,8 @@ lbl_glue <- function (
#' This is useful when the left endpoint unambiguously indicates the
#' interval. In other cases it may give errors due to duplicate labels.
#'
#' `lbl_endpoint()` is `r lifecycle::badge("deprecated")`. Do not use it.
#' `lbl_endpoint()` is `r lifecycle::badge("defunct")` and gives an
#' error since santoku 1.0.0.
#'
#' @inherit label-doc
#' @inherit first-last-doc
Expand Down Expand Up @@ -351,7 +352,7 @@ lbl_endpoints <- function (
assert_that(is.flag(left))

if (! isFALSE(raw)) {
lifecycle::deprecate_soft("0.9.0", "lbl_endpoints(raw)", "chop(raw)")
lifecycle::deprecate_warn("0.9.0", "lbl_endpoints(raw)", "chop(raw)")
}

label <- if (left) "{l}" else "{r}"
Expand All @@ -367,9 +368,8 @@ lbl_endpoint <- function (
raw = FALSE,
left = TRUE
) {
lifecycle::deprecate_warn(when = "0.8.0", what = "lbl_endpoint()",
lifecycle::deprecate_stop(when = "0.8.0", what = "lbl_endpoint()",
with = "lbl_endpoints()")
lbl_endpoints(fmt = fmt, raw = raw, left = left)
}


Expand Down Expand Up @@ -549,17 +549,14 @@ lbl_seq <- function(start = "a") {
}


#' Label chopped intervals in a user-defined sequence
#' Defunct: label chopped intervals in a user-defined sequence
#'
#' `r lifecycle::badge("deprecated")`
#' `r lifecycle::badge("defunct")`
#'
#' `lbl_manual()` is deprecated because it is little used and is not closely
#' related to the rest of the package. It also risks mislabelling intervals, e.g.
#' if intervals are extended.
#'
#' `lbl_manual()` uses an arbitrary sequence to label
#' intervals. If the sequence is too short, it will be pasted with itself and
#' repeated.
#' `lbl_manual()` is defunct since santoku 1.0.0. It is little used and is not
#' closely related to the rest of the package. It also risks mislabelling
#' intervals, e.g. if intervals are extended. Use of `lbl_manual()` will give
#' an error.
#'
#' @param sequence A character vector of labels.
#' @inherit label-doc
Expand All @@ -571,22 +568,12 @@ lbl_seq <- function(start = "a") {
#' @keywords internal
#'
#' @examples
#' \dontrun{
#' chop(1:10, c(2, 5, 8), lbl_manual(c("w", "x", "y", "z")))
#' # ->
#' chop(1:10, c(2, 5, 8), labels = c("w", "x", "y", "z"))
#' }
lbl_manual <- function (sequence, fmt = "%s") {
lifecycle::deprecate_warn("0.9.0", "lbl_manual()",
lifecycle::deprecate_stop("0.9.0", "lbl_manual()",
details = "Just specify `labels = sequence` instead.")
assert_that(is_format(fmt))

if (anyDuplicated(sequence) > 0L) stop("`sequence` contains duplicate items")
function (breaks, raw = NULL) {
ls <- sequence
latest <- ls
while (length(breaks) - 1 > length(ls)) {
latest <- paste0(latest, sequence)
ls <- c(ls, latest)
}
apply_format(fmt, ls[seq(1L, length(breaks) - 1)])
}
}
2 changes: 1 addition & 1 deletion README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ knitr::opts_chunk$set(

<!-- badges: start -->
[![CRAN status](https://www.r-pkg.org/badges/version/santoku)](https://CRAN.R-project.org/package=santoku)
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html)
[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)
[![CRAN Downloads Per Month](http://cranlogs.r-pkg.org/badges/santoku)](https://CRAN.R-project.org/package=santoku)
[![R-universe](https://hughjonesd.r-universe.dev/badges/santoku)](https://hughjonesd.r-universe.dev/santoku)
[![R-CMD-check](https://github.com/hughjonesd/santoku/workflows/R-CMD-check/badge.svg)](https://github.com/hughjonesd/santoku/actions)
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[![CRAN
status](https://www.r-pkg.org/badges/version/santoku)](https://CRAN.R-project.org/package=santoku)
[![Lifecycle:
experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html)
stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)
[![CRAN Downloads Per
Month](http://cranlogs.r-pkg.org/badges/santoku)](https://CRAN.R-project.org/package=santoku)
[![R-universe](https://hughjonesd.r-universe.dev/badges/santoku)](https://hughjonesd.r-universe.dev/santoku)
Expand Down Expand Up @@ -113,10 +113,10 @@ Chop into fixed-width intervals:

``` r
chop_width(runif(10), 0.1)
#> [1] [0.1399, 0.2399) [0.5399, 0.6399) [0.5399, 0.6399) [0.5399, 0.6399)
#> [5] [0.6399, 0.7399) [0.3399, 0.4399) [0.8399, 0.9399] [0.8399, 0.9399]
#> [9] [0.5399, 0.6399) [0.1399, 0.2399)
#> 5 Levels: [0.1399, 0.2399) [0.3399, 0.4399) ... [0.8399, 0.9399]
#> [1] [0.1068, 0.2068) [0.6068, 0.7068) [0.9068, 1.007] [0.006763, 0.1068)
#> [5] [0.9068, 1.007] [0.3068, 0.4068) [0.6068, 0.7068) [0.1068, 0.2068)
#> [9] [0.4068, 0.5068) [0.5068, 0.6068)
#> 7 Levels: [0.006763, 0.1068) [0.1068, 0.2068) ... [0.9068, 1.007]
```

Or into fixed-size groups:
Expand Down
3 changes: 2 additions & 1 deletion man/lbl_endpoints.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 8 additions & 9 deletions man/lbl_manual.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 3 additions & 11 deletions tests/testthat/test-labels.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,9 @@
brackets <- function (x) paste0("(", x, ")")


test_that("lbl_manual", {
brk <- brk_res(brk_manual(1:3, rep(TRUE, 3)))

lifecycle::expect_deprecated(lbl_manual(letters))

withr::local_options(lifecycle_verbosity = "quiet")

expect_error(lbl_manual(c("a", "a")))
expect_equivalent(lbl_manual(letters[1])(brk), c("a", "aa"))
test_that("lbl_manual and lbl_endpoint are defunct", {
lifecycle::expect_defunct(lbl_manual(letters))
lifecycle::expect_defunct(lbl_endpoint()(lbrk))
})


Expand Down Expand Up @@ -196,8 +190,6 @@ test_that("lbl_endpoints arguments", {
lbl_endpoints(fmt = list(nsmall = 2, decimal.mark = ","))(lbrk),
c("1,00", "3,00")
)

lifecycle::expect_deprecated(lbl_endpoint()(lbrk))
})


Expand Down

0 comments on commit d371f47

Please sign in to comment.