foldr: Fold a vector or list from the right

View source: R/map.R

foldrR Documentation

Fold a vector or list from the right

Description

Reduce .x with the two-argument function .f, associating from the right, a thin wrapper around base::Reduce() with right = TRUE. With .accumulate = TRUE the intermediate results are returned as well.

Usage

foldr(.x, .f, .init = NULL, .accumulate = FALSE, .simplify = TRUE)

Arguments

.x

A vector or list.

.f

A two-argument reducing function.

.init

Optional initial value.

.accumulate

Return intermediate accumulated values.

.simplify

Simplify accumulated results when possible.

Value

The folded value, or accumulated values when .accumulate = TRUE.

Examples

foldr(1:4, `+`)
foldr(letters[1:4], paste0, .accumulate = TRUE)

basetable documentation built on Sept. 18, 2026, 9:13 a.m.