Description Usage Arguments Examples
Allows the user to perform a while-like
loop without breaking out of a pipeline.
To maintain the flow of a pipeline, it is recommended
to use [fseq
][] style arguments (i.e. pipelines) for the
fun
argument.
Within the while_pipe()
, users can use the .counter
variable
to reference how many iterations have been performed so far.
1 | while_pipe(data, cond, fun)
|
data |
the data being passed through the pipeline. |
cond |
an expression to be evaluated in the context of |
fun |
pipeline to perform until |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | sample(100, 1) %>%
runif() %>%
pipe_cat("Current length: ", length(.), "\n") %>%
while_pipe(
length(.) > 1,
. %>%
diff() %>%
magrittr::divide_by(2)
)
tibble::tibble(x = runif(5)) %>%
while_pipe(
.counter <= 5,
. %>%
dplyr::mutate(!!paste0("x_", .counter) := x - x[.counter])
)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.