library(dplyr)
library(dtrackr)
iris %>% track() %>% group_by(Species) %>% include_any(
Petal.Length > 5 ~ "{.included} long ones",
Petal.Length < 2 ~ "{.included} short ones"
) %>% history()
# simultaneous evaluation of criteria:
data.frame(a = 1:10) %>%
track() %>%
include_any(
# These two criteria identify the same value and one item is excluded
a > 1 ~ "{.included} value > 1",
a != min(a) ~ "{.included} everything but the smallest value",
) %>%
status() %>%
history()
# the behaviour is equivalent to dplyr's filter function:
data.frame(a=1:10) %>%
dplyr::filter(a > 1, a != min(a)) %>%
nrow()
# step-wise evaluation of criteria results in a different output
data.frame(a = 1:10) %>%
track() %>%
# Performing the same exclusion sequentially results in 2 items
# being excluded as the criteria no longer identify the same
# item.
include_any(a > 1 ~ "{.included} value > 1") %>%
include_any(a != min(a) ~ "{.included} everything but the smallest value") %>%
status() %>%
history()
# the behaviour is equivalent to dplyr's filter function:
data.frame(a=1:10) %>%
dplyr::filter(a > 1) %>%
dplyr::filter(a != min(a)) %>%
nrow()
Run the code above in your browser using DataLab