-
Notifications
You must be signed in to change notification settings - Fork 34
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
Is there a way to assert elementwise over a whole data.frame? #77
Comments
You probably need |
@sursh Thank you so much for the kind words about the library! |
I agree with this behaviour but it might be a good idea to throw an error if
Will fail with an error like "Assert requires columns to be selected" but
should succeed. Should only need a couple of lines of code - I can submit a push request later this week to demonstrate exactly what I mean. |
Yes, I'd definitely suggest erring on the side of throwing an error—much safer that way. @richardjtelford that sounds great! You could make the error message even more helpful like this, telling them how to run it over all columns: "Assert requires columns to be selected. Select all columns with everything()" |
That sounds like a great idea! |
Done! Thanks for reporting it :) |
Hi there, this library looks awesome! My first use case for it is to check an entire data.frame, let's say for NaNs.
I wrote a function
contains_no_nans
that returns FALSE if there are any NaNs in my data.frame. It's working as expected when I dodf %>% contains_no_nans
. However, I'm not sure how to use it with assertr. To my surprise, this passed even when there were NaNs:my_df %>% assert(contains_no_nans)
I was surprised because I was extrapolating from your example
assert(within_bounds(0,Inf, include.lower=FALSE), -mpg)
. I figured that looks at everything except mpg, so if I leave out the second argument it should look at all columns.I suspect it's because you're using select under the hood and if you don't pass any arguments into select(), it returns an Nx0 tibble which, well, has no NaNs. So a workaround would be to call it like this:
my_df %>% assert(contains_no_nans, colnames(.))
Is this the best way?
And whether it is or isn't, perhaps consider adding a note about this to the vignette. It's true that you don't claim that
assert
can do this, but it's a subtle thing and if people are in a hurry it could lead to asserts passing when they shouldn't.Thanks again for this great library! This will save me lots of heartache.
The text was updated successfully, but these errors were encountered: