assertr
assertr copied to clipboard
When multiple comma-separated columns are selected in assert_rows, it gives an error when building the violations data.frame
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 column
s 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.
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!
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)
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)
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!