reduce_right | R Documentation |
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:
# Before: reduce_right(1:3, f) # After: reduce(rev(1:3), f)
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.
reduce_right(.x, .f, ..., .init)
reduce2_right(.x, .y, .f, ..., .init)
accumulate_right(.x, .f, ..., .init)
.x |
A list or atomic vector. |
.f |
For For The reduction terminates early if |
... |
Additional arguments passed on to the reduce function. We now generally recommend against using # Instead of x |> reduce(f, 1, 2, collapse = ",") # do: x |> reduce(\(x, y) f(x, y, 1, 2, collapse = ",")) This makes it easier to understand which arguments belong to which function and will tend to yield better error messages. |
.init |
If supplied, will be used as the first value to start
the accumulation, rather than using |
.y |
For |
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.