I would like to use the accumulate
function with two input vectors and the reduce2
function. The documentation for accumulate
implies that two input vectors can be given and that accumulate
can work with reduce2
. However, I am having trouble.
Here is an example, inspired by the documentation from reduce2
.
This is the example from reduce2
> paste2 <- function(x, y, sep = ".") paste(x, y, sep = sep)
> letters[1:4] %>% reduce2(.y=c("-", ".", "-"), paste2)
[1] "a-b.c-d"
Here are several attempts to use accumulate
similarly to reduce2
. None properly iterate through both letters[1:4]
and c("-",".","-")
.
> letters[1:4] %>% accumulate(.y=c("-", ".", "-"),paste2)
Error in .f(x, y, ...) : unused argument (.y = c("-", ".", "-"))
> letters[1:4] %>% accumulate(c("-", ".", "-"),paste2)
[[1]]
[1] "a"
[[2]]
NULL
> letters[1:4] %>% accumulate(sep=c("-", ".", "-"),paste2)
[1] "a" "a-b" "a-b-c" "a-b-c-d"
How would I use accumulate
to see the intermediate results given by the reduce2
example?