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

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

Open
theunis opened this issue Dec 27, 2018 · 4 comments

Comments

@theunis
Copy link

theunis commented Dec 27, 2018

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.

@tonyfischetti
Copy link
Owner

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!

@11rchitwood
Copy link

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
Copy link

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)

@tonyfischetti
Copy link
Owner

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!

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

3 participants