Description Usage Arguments Details Value Examples
View source: R/conditional_filter.R
conditional_filter()
returns a specified result if the condition is met, or TRUE otherwise
1 | conditional_filter(condition, success)
|
condition |
A conditional statement |
success |
The result if the conditional statement returns TRUE |
This function is used to reactively filter a dataframe with dplyr::filter()
.
If the condition is met, the filtering condition specified in success
will be returned,
filtering the dataframe. If the condition is not met, it will return TRUE.
Because filter()
accepts any row that returns TRUE, this returns the unfiltered dataframe.
The success parameter if the condition is met, or TRUE if not
1 2 3 4 5 6 7 | # Condition returns TRUE, filters successfully
x <- 5
df <- dplyr::filter(accidents, conditional_filter(x == 5, day.night == "night"))
# Condition returns FALSE, filter() sees TRUE, so does not filter dataframe
x <- 3
df <- dplyr::filter(accidents, conditional_filter(x == 5, day.night == "night"))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.