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

predicate in_set inverse with missing values #133

Open
AnthonyEbert opened this issue May 24, 2024 · 0 comments
Open

predicate in_set inverse with missing values #133

AnthonyEbert opened this issue May 24, 2024 · 0 comments

Comments

@AnthonyEbert
Copy link

AnthonyEbert commented May 24, 2024

With the predicate in_set with argument inverse=TRUE, the argument allow.na works in the opposite way to what is expected.

library(dplyr)
library(survival)

veteran_totals = veteran %>%
  group_by(celltype) %>%
  summarise(cell_total = n())
  
veteran_totals$cell_total[1] <- NA
 
veteran_totals %>% assertr::assert(cell_total, predicate = assertr::in_set(10:20, inverse = TRUE, allow.na = TRUE)) 
>Column 'cell_total' violates assertion 'assertr::in_set(10:20, inverse = TRUE, allow.na = TRUE)' 1 time
>  verb redux_fn                                               predicate     column index value
>1 assert       NA assertr::in_set(10:20, inverse = TRUE, allow.na = TRUE) cell_total     1    NA
>
>Error: assertr stopped execution

veteran_totals %>% assertr::assert(cell_total, predicate = assertr::in_set(10:20, inverse = TRUE, allow.na = FALSE))
> # A tibble: 4 × 2
> celltype  cell_total
>  <fct>          <int>
>1 squamous          NA
>2 smallcell         48
>3 adeno             27
>4 large             27

I guess you could fix this with a line allow.na = ifelse(inverse, !allow.na, allow.na) in the first line of the function. ?

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

No branches or pull requests

1 participant