From 6ccb396f86053c0a3373406a28669341a34a1d0c Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Tue, 20 Aug 2024 15:28:18 -0500 Subject: [PATCH 1/2] Move `reduce_right()` notes I think it makes more sense to put them in the `reduce_right()` docs, rather than the `reduce()` docs. --- R/reduce.R | 49 +++++++++++++++++++-------------------------- man/reduce.Rd | 25 ----------------------- man/reduce_right.Rd | 23 ++++++++++++++++++--- 3 files changed, 41 insertions(+), 56 deletions(-) diff --git a/R/reduce.R b/R/reduce.R index d491ae1c..2b4f5d56 100644 --- a/R/reduce.R +++ b/R/reduce.R @@ -43,30 +43,6 @@ #' the left produces a left-leaning nested list (or tree), while #' reducing `list()` from the right produces a right-leaning list. #' -#' @section Life cycle: -#' -#' `reduce_right()` is soft-deprecated as of purrr 0.3.0. Please use -#' the `.dir` argument of `reduce()` instead. Note that the algorithm -#' has changed. Whereas `reduce_right()` computed `f(f(3, 2), 1)`, -#' `reduce(.dir = \"backward\")` computes `f(1, f(2, 3))`. This is the -#' standard way of reducing from the right. -#' -#' To update your code with the same reduction as `reduce_right()`, -#' simply reverse your vector and use a left reduction: -#' -#' ```{r, eval = FALSE} -#' # Before: -#' reduce_right(1:3, f) -#' -#' # After: -#' reduce(rev(1:3), f) -#' ``` -#' -#' `reduce2_right()` is soft-deprecated as of purrr 0.3.0 without -#' replacement. It is not clear what algorithmic properties should a -#' right reduction have in this case. Please reach out if you know -#' about a use case for a right reduction with a ternary function. -#' #' @seealso [accumulate()] for a version that returns all intermediate #' values of the reduction. #' @examples @@ -515,12 +491,29 @@ accumulate_names <- function(nms, init, dir) { #' @description #' `r lifecycle::badge("deprecated")` #' -#' These functions were deprecated in purrr 0.3.0. Please use the -#' `.dir` argument of [reduce()] instead, or reverse your vectors -#' and use a left reduction. +#' `reduce_right()` is soft-deprecated as of purrr 0.3.0. Please use +#' the `.dir` argument of `reduce()` instead. Note that the algorithm +#' has changed. Whereas `reduce_right()` computed `f(f(3, 2), 1)`, +#' `reduce(.dir = \"backward\")` computes `f(1, f(2, 3))`. This is the +#' standard way of reducing from the right. #' -#' @inheritParams reduce +#' To update your code with the same reduction as `reduce_right()`, +#' simply reverse your vector and use a left reduction: +#' +#' ```R +#' # Before: +#' reduce_right(1:3, f) +#' +#' # After: +#' reduce(rev(1:3), f) +#' ``` #' +#' `reduce2_right()` is soft-deprecated as of purrr 0.3.0 without +#' replacement. It is not clear what algorithmic properties should a +#' right reduction have in this case. Please reach out if you know +#' about a use case for a right reduction with a ternary function. +#' +#' @inheritParams reduce #' @keywords internal #' @export reduce_right <- function(.x, .f, ..., .init) { diff --git a/man/reduce.Rd b/man/reduce.Rd index 69ea6388..1a35a1e4 100644 --- a/man/reduce.Rd +++ b/man/reduce.Rd @@ -70,31 +70,6 @@ the left produces a left-leaning nested list (or tree), while reducing \code{list()} from the right produces a right-leaning list. } -\section{Life cycle}{ - - -\code{reduce_right()} is soft-deprecated as of purrr 0.3.0. Please use -the \code{.dir} argument of \code{reduce()} instead. Note that the algorithm -has changed. Whereas \code{reduce_right()} computed \code{f(f(3, 2), 1)}, -\verb{reduce(.dir = \\"backward\\")} computes \code{f(1, f(2, 3))}. This is the -standard way of reducing from the right. - -To update your code with the same reduction as \code{reduce_right()}, -simply reverse your vector and use a left reduction: - -\if{html}{\out{
}}\preformatted{# Before: -reduce_right(1:3, f) - -# After: -reduce(rev(1:3), f) -}\if{html}{\out{
}} - -\code{reduce2_right()} is soft-deprecated as of purrr 0.3.0 without -replacement. It is not clear what algorithmic properties should a -right reduction have in this case. Please reach out if you know -about a use case for a right reduction with a ternary function. -} - \examples{ # Reducing `+` computes the sum of a vector while reducing `*` # computes the product: diff --git a/man/reduce_right.Rd b/man/reduce_right.Rd index f3478e4f..8ae24fe7 100644 --- a/man/reduce_right.Rd +++ b/man/reduce_right.Rd @@ -52,8 +52,25 @@ should be 1 element shorter than \code{.x}.} \description{ \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} -These functions were deprecated in purrr 0.3.0. Please use the -\code{.dir} argument of \code{\link[=reduce]{reduce()}} instead, or reverse your vectors -and use a left reduction. +\code{reduce_right()} is soft-deprecated as of purrr 0.3.0. Please use +the \code{.dir} argument of \code{reduce()} instead. Note that the algorithm +has changed. Whereas \code{reduce_right()} computed \code{f(f(3, 2), 1)}, +\verb{reduce(.dir = \\"backward\\")} computes \code{f(1, f(2, 3))}. This is the +standard way of reducing from the right. + +To update your code with the same reduction as \code{reduce_right()}, +simply reverse your vector and use a left reduction: + +\if{html}{\out{
}}\preformatted{# Before: +reduce_right(1:3, f) + +# After: +reduce(rev(1:3), f) +}\if{html}{\out{
}} + +\code{reduce2_right()} is soft-deprecated as of purrr 0.3.0 without +replacement. It is not clear what algorithmic properties should a +right reduction have in this case. Please reach out if you know +about a use case for a right reduction with a ternary function. } \keyword{internal} From 95870f7405d2dcb4c5115199b62f7ad8c54e1047 Mon Sep 17 00:00:00 2001 From: Hadley Wickham Date: Tue, 20 Aug 2024 15:29:44 -0500 Subject: [PATCH 2/2] Deprecated, not soft-deprecated --- R/reduce.R | 2 +- man/reduce_right.Rd | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/reduce.R b/R/reduce.R index 2b4f5d56..74c891f6 100644 --- a/R/reduce.R +++ b/R/reduce.R @@ -508,7 +508,7 @@ accumulate_names <- function(nms, init, dir) { #' reduce(rev(1:3), f) #' ``` #' -#' `reduce2_right()` is soft-deprecated as of purrr 0.3.0 without +#' `reduce2_right()` is deprecated as of purrr 0.3.0 without #' replacement. It is not clear what algorithmic properties should a #' right reduction have in this case. Please reach out if you know #' about a use case for a right reduction with a ternary function. diff --git a/man/reduce_right.Rd b/man/reduce_right.Rd index 8ae24fe7..74009435 100644 --- a/man/reduce_right.Rd +++ b/man/reduce_right.Rd @@ -68,7 +68,7 @@ reduce_right(1:3, f) reduce(rev(1:3), f) }\if{html}{\out{}} -\code{reduce2_right()} is soft-deprecated as of purrr 0.3.0 without +\code{reduce2_right()} is deprecated as of purrr 0.3.0 without replacement. It is not clear what algorithmic properties should a right reduction have in this case. Please reach out if you know about a use case for a right reduction with a ternary function.