This may/may not be a duplicate of How can I use accumulate like reduce2 function in purrr? but I couldn't really understand the case being discussed there so asking this again.
I am trying to understand the working of purrr::accummulate
especially when passing 3 arguments. Here's documentation for it -
.x - A list or atomic vector.
.f - For reduce(), a 2-argument function. The function will be passed the accumulated value as the first argument and the "next" value as the second argument. For reduce2(), a 3-argument function. The function will be passed the accumulated value as the first argument, the next value of .x as the second argument, and the next value of .y as the third argument.
Based on above documentation -
library(purrr)
# 2-argument use is pretty straightforward
accumulate(.x = 1:3, .f = sum)
[1] 1 3 6 # 1, 1+2, 1+2+3
# 3-argument result seems weird
accumulate(.x = 1:3, .y = 1:2, .f = sum)
[1] 1 6 12 # seems like 1, 1+2+3, 1+2+3+3+3
# expecting 1 4 9 i.e. 1, 1+2+1, 1+2+1+3+2
# reduce2 works correctly and gives 9
reduce2(.x = 1:3, .y = 1:2, .f = sum)
[1] 9
# it seems to take sum(y) as third argument instead of "next value of .y"
Am I missing something?