Skip to content

Check a rowwise assertion #372

Answered by rich-iannone
maia-sh asked this question in Q&A
Discussion options

You must be logged in to vote

@maia-sh

For this, I'd recommend using the col_vals_expr() function to create an expectation that uses an expression:

library(dplyr)
library(pointblank)

df <- tribble(
  ~a, ~b, ~c,
  1, 2, 3,    # should pass (no NAs)
  NA, NA, NA, # should fail (completely NAs)
  2, NA, 6    # should pass (partial NAs)
)

# Create an agent and use `col_vals_expr()` to evaluate
# a more complex expression on a per-row basis
agent <-
  df %>%
    create_agent() %>%
    col_vals_expr(expr = ~ !(is.na(a) & is.na(b) & is.na(c))) %>%
    interrogate()

# This shows that only the second row fails
get_data_extracts(agent, i = 1)
#> # A tibble: 1 × 3
#>       a     b     c
#>   <dbl> <dbl> <dbl>
#> 1    NA    N…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by rich-iannone
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants