0

I want to automatically verify assumptions on columns of my tibble using assertr. The problem is that I have hundreds of columns so I can't apply them column by column. Data looks like this:

df <- tibble(
  x = c(1,0,1,1,2), 
  y = c('A', 'B', 'C', 'D', 'A'), 
  z = c(1/3, 4, 5/7, 100, 3))

Then I have another tibble which describes types of columns:

df_map <- tibble(
  col = c('x','y','z'), 
  col_type = c('POSSIBLE VALUES 0 AND 1', 'LESS THAN 1 MISSING VALUE', 'POSITIVE VALUE')
)

This can be written like:

df %>%  
  assert(in_set(0,1), x) %>%
  assert_rows(num_row_NAs, within_bounds(0,1), y) %>%
  verify(z > 0)

My question is how to apply these verifications (or any other) with this mapping so I don't need to write them for every single column.

mihagazvoda
  • 1,057
  • 13
  • 23
  • At the very least you'll need to be able to create functions that check the conditions mentioned in col_type. R isn't going to magically know what you mean by those descriptions. – Dason Aug 17 '19 at 19:37
  • No, I don't. Please, take a look at the updated question. – mihagazvoda Aug 18 '19 at 08:22

0 Answers0