Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add assert_count_true() to verify that an expected number of values are TRUE #573

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

billdenney
Copy link
Collaborator

Related to #539

I use a variant of this often in my data pipelines where I want to select a certain number of values and be sure that I'm only getting the number I expect. For example, I want to change one date for one person, and I want to be sure that I only change that one date:

# We are very young
my_data <- data.frame(name = c("Bill", "Sam"), birthdate = c("2024-05-22", "2024-05-22"))
my_data |>
  dplyr::mutate(
    birthdate =
      dplyr::case_when(
        assert_count_true(name == "Bill" & birthdate == "2024-05-22") ~ "2024-05-23",
        TRUE ~ birthdate
      )
  )

@billdenney billdenney requested a review from sfirke May 22, 2024 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant