# NOT RUN {
1:10 %>%
when(
sum(.) <= 50 ~ sum(.),
sum(.) <= 100 ~ sum(.)/2,
~ 0
)
1:10 %>%
when(
sum(.) <= x ~ sum(.),
sum(.) <= 2*x ~ sum(.)/2,
~ 0,
x = 60
)
iris %>%
subset(Sepal.Length > 10) %>%
when(
nrow(.) > 0 ~ .,
~ iris %>% head(10)
)
iris %>%
head %>%
when(nrow(.) < 10 ~ .,
~ stop("Expected fewer than 10 rows."))
# }
Run the code above in your browser using DataLab