Description Usage Arguments Details Examples
View source: R/accumulate-while.R
Perform a function to transform an object multiple times, until a predicate is not satisfied.
1 | accumulate_while(.x, .f, .p, ..., .compare = FALSE, .max = 1e+05)
|
.x |
Starting value |
.f |
Function to apply to transform each step to the next |
.p |
A predicate applied to each intermediate step: if false, it stops the iteration |
... |
Extra arguments passed to .f |
.compare |
Whether the predicate will be given the last two steps rather than just the most recent. |
.max |
Maximum number of iterations to perform. Give |
I've suggested a function like this in an issue on purrr: https://github.com/hadley/purrr/issues/253. I've put it here so I can use it personally in the meantime. If it gets added to purrr, I will remove it from drlib.
1 2 3 4 | accumulate_while(1, ~ . + 1, ~ . < 5)
# accumulate until difference is within some tolerance
accumulate_while(1, ~ . / 2, ~ abs(.x - .y) > 1e-4, .compare = TRUE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.