-
Notifications
You must be signed in to change notification settings - Fork 29
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
mid-pipe assertions #41
Comments
I'd find this really useful! I honestly still have trouble using the |
Consider using assertr for this functionality: https://cran.r-project.org/web/packages/assertr/vignettes/assertr.html |
Isn't this what the env argument of assert_that() is for? Below, I assign to global variable d . I then show three pipes with an assert_that() call embedded with the tee operator, and a mutate() on the tibble at the end. One assert_that() should return TRUE; one tests a column of the tibble and should fail; the other tests d and should fail. They seem to work as intended.
|
Often when troubleshooting a "long"
%>%
pipe, if I need to test assertions on the data, I need to interrupt the pipe (if no grouping present) or use ado()
block (both with/without grouping).works as one might expect. If you run this with
cyls <- 4
, though, you'll see thatvs=0
only contains one row, and errors out.In order to assert that sufficient data is present, you either need to use a
do()
block or break up the pipe:It would be nice to be able to test the assertion mid-pipe:
Granted, in this contrived example, the error should be sufficient, but it's not hard to consider longer pipelines where calculation should not continue without verified conditions.
I think assertion-companion functions such as
assert_pipe_stop
and perhapsassert_pipe_warning
might be useful. I think it makes more sense to extendassertthat
to be pipe-aware vice adding assertions todplyr
or another of thetidyverse
packages.Thoughts?
I'm willing to work on a PR, though admittedly I'm not as proficient at NSE, where these functions would heavily reside.
The text was updated successfully, but these errors were encountered: