assertr icon indicating copy to clipboard operation
assertr copied to clipboard

When multiple comma-separated columns are selected in assert_rows, it gives an error when building the violations data.frame

Open theunis opened this issue 5 years ago • 4 comments

Example:

mtcars[2:4, "mpg"] <- NA
mtcars[2:4, "am"] <- NA
mtcars %>% 
  assert_rows(num_row_NAs, within_bounds(0,1), mpg, am)

gives

Error in data.frame(verb = verb, redux_fn = name.of.rowredux.fn, predicate = name.of.predicate,  : 
  arguments imply differing number of rows: 1, 2, 3

This error resides in the function make.assertr.assert_rows.error. Right here:

error_df <- data.frame(verb = verb, redux_fn = name.of.rowredux.fn, 
    predicate = name.of.predicate, column = column, index = loc.violations, 
    value = offending.elements)

The columns need to be collated in some way so that it becomes a vector of length 1, before it is inserted into the error_df data.frame.

theunis avatar Dec 27 '18 19:12 theunis

Heads up, pretty soon there are going to a big merge into this repo (from a fork) If this error persists after the merge, I'll definitely have to fix this

Thanks for bringing this to my attention!

tonyfischetti avatar Oct 30 '19 22:10 tonyfischetti

I'm having the same error, but with col_concat/is_uniq:

library(assertr)

mtcars |>
  assert_rows(col_concat, is_uniq, mpg, cyl, hp)
#> Error in data.frame(verb = verb, redux_fn = name.of.rowredux.fn, predicate = name.of.predicate, : arguments imply differing number of rows: 1, 3, 2

Created on 2022-06-27 by the reprex package (v2.0.1)

11rchitwood avatar Jun 27 '22 15:06 11rchitwood

I think I'm having the same error, but with col_concat/is_uniq

library(assertr)

mtcars |>
  assert_rows(col_concat, is_uniq, mpg, cyl, hp)
#> Error in data.frame(verb = verb, redux_fn = name.of.rowredux.fn, predicate = name.of.predicate, : arguments imply differing number of rows: 1, 3, 2

Created on 2022-06-27 by the reprex package (v2.0.1)

11rchitwood avatar Jun 27 '22 15:06 11rchitwood

Got to the bottom of this. It works if you put it in a vector of unquoted column names. For example...

library(assertr)
library(magrittr)

mtcars |>
  assert_rows(col_concat, is_uniq, c(mpg, cyl, hp))

mtcars[2:4, "mpg"] <- NA
mtcars[2:4, "am"] <- NA
mtcars %>% 
  assert_rows(num_row_NAs, within_bounds(0,1), c(mpg, am))

I'll update the docs to reflect this! Thanks for catching it!

tonyfischetti avatar Jul 10 '22 15:07 tonyfischetti