Description Usage Arguments Details Value Examples
View source: R/tidy_filter_null.R
For use inside dplyr::filter()
operations where sometimes it is desired to
filter nothing.
1 2 3 4 5 | tidy_filter_null(
x,
filter_value = NULL,
filter_how = c("==", ">=", ">", "<=", "<", "in")
)
|
x |
A string or vector of strings with the column name(s) to apply the filter on. |
filter_value |
A value (or vector when |
filter_how |
A string with the filtering operation: "==", ">=", ">",
"<=", "<" or "in", where "in" is for applying vector filters with |
This function is useful when there is a dplyr::filter()
operation
on a data frame but it is not always desirable to filter the data frame.
A good example is a Shiny
dashboard that returns a plot or table of the
filtered data or of the whole dataset, depending on the input from the
user.
The filtered data frame or the original data frame when
filter_value
is NULL
or NA
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | library(experienceAnalysis)
# Filter gear and carb to be 2 or 3
mtcars %>%
dplyr::filter(
dplyr::across(
c("gear", "carb"),
~ experienceAnalysis::tidy_filter_null(., filter_value = 2:3,
filter_how = "in")
)
)
# Filter nothing (returns original data frame)
mtcars %>%
dplyr::filter(
dplyr::across(
c("gear", "carb"),
~ experienceAnalysis::tidy_filter_null(., filter_value = NULL)
)
)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.