-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Closed
Description
A tidy version of stopifnot which respects groups
stop_if_not <- function(.data, ...){
statements <- rlang::quos(...)
dplyr::mutate(.data, stopifnot(!!!statements))
return(.data)
}
Example
iris |> group_by(Species) |> stop_if_not(n() == 50)
# Passes
iris |> group_by(Species) |> stop_if_not(n() != 50)
# Fails
starwars |> stop_if_not(n_distinct(name) == n())
# Passes
starwars |> stop_if_not(if_all(where(is.numeric), ~ .x > 0))
# Fails
starwars |> stop_if_not(if_all(where(is.numeric), ~ .x > 0 | is.na(.x)))
# Passes
Metadata
Metadata
Assignees
Labels
No labels