conditional_filter: Return a result conditionally

Description Usage Arguments Details Value Examples

View source: R/conditional_filter.R

Description

conditional_filter() returns a specified result if the condition is met, or TRUE otherwise

Usage

1

Arguments

condition

A conditional statement

success

The result if the conditional statement returns TRUE

Details

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.

Value

The success parameter if the condition is met, or TRUE if not

Examples

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"))

ahvickers/accidenttracker documentation built on Dec. 18, 2021, 11:26 p.m.