Description Usage Arguments Examples
Allows the user to perform an if/else-like
branch 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 fun
and
elsefun
, however any function can be used.
1 |
data |
the data being passed through the pipeline |
predicate |
logical statement, a function or an expression that
can be evaluated in the context of |
fun |
pipeline to follow if |
elsefun |
pipeline to follow if |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | 1 %>%
magrittr::multiply_by(2) %>%
if_branch(
. %>% magrittr::equals(2),
. %>%
magrittr::multiply_by(3) %>%
magrittr::add(2)
) %>%
magrittr::multiply_by(2)
tibble::tibble(x = rnorm(100), y = rnorm(100)) %>%
dplyr::mutate(z = x + y) %>%
if_branch(
mean(z) > 0,
. %>%
pipe_cat("z is high\n\n"),
. %>%
dplyr::select(-z) %>%
pipe_cat("z is low, so it was dropped\n\n")
)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.