-
Notifications
You must be signed in to change notification settings - Fork 39
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
check_that
throws cryptic errors when run after a pipeline step fails
#153
Comments
The first error msg I see comes from filter. This is not a validate function. I'd go after that first. Maybe use dplyr::filter.and similar for the other functions? (I'm not near a computer now so I can't test) |
@markvanderloo Oh yeah, I know the error is coming from suppressPackageStartupMessages({
library(dplyr)
library(validate)
})
iris <- tibble::as_tibble(iris)
## Filtering works fine
iris %>%
filter(
Sepal.Length > 5
)
#> # A tibble: 118 x 5
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#> <dbl> <dbl> <dbl> <dbl> <fct>
#> 1 5.1 3.5 1.4 0.2 setosa
#> 2 5.4 3.9 1.7 0.4 setosa
#> 3 5.4 3.7 1.5 0.2 setosa
#> 4 5.8 4 1.2 0.2 setosa
#> 5 5.7 4.4 1.5 0.4 setosa
#> 6 5.4 3.9 1.3 0.4 setosa
#> 7 5.1 3.5 1.4 0.3 setosa
#> 8 5.7 3.8 1.7 0.3 setosa
#> 9 5.1 3.8 1.5 0.3 setosa
#> 10 5.4 3.4 1.7 0.2 setosa
#> # … with 108 more rows
## Filtering and then piping into check_that also works fine
iris %>%
filter(
Sepal.Length > 5
) %>%
check_that(
Sepal.Length > 5
)
#> Object of class 'validation'
#> Call:
#> check_that(., Sepal.Length > 5)
#>
#> Rules confronted: 1
#> With fails : 0
#> With missings: 0
#> Threw warning: 0
#> Threw error : 0
## problem: When `filter` fails, `check_that` throws a gibberish error
iris %>%
filter(
foo > 3
) %>%
check_that(
Sepal.Length < 1000
)
#> Error in (function (cond) : error in evaluating the argument 'dat' in selecting a method for function 'confront': Problem with `filter()` input `..1`.
#> ℹ Input `..1` is `foo > 3`.
#> x object 'foo' not found
## big problem: Multiple `check_that`s means multiple repetitions of this error
## arbitrarily many of them, as the chain gets bigger
iris %>%
filter(
foo > 3
) %>%
check_that(
Sepal.Length < 1000
) %>%
filter(
foo > 3
) %>%
check_that(
Sepal.Length < 1000
) %>%
filter(
foo > 3
) %>%
check_that(
Sepal.Length < 1000
) %>%
filter(
foo > 3
) %>%
check_that(
Sepal.Length < 1000
) %>%
filter(
foo > 3
) %>%
check_that(
Sepal.Length < 1000
)
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'dat' in selecting a method for function 'confront': error in evaluating the argument 'dat' in selecting a method for function 'confront': error in evaluating the argument 'dat' in selecting a method for function 'confront': error in evaluating the argument 'dat' in selecting a method for function 'confront': error in evaluating the argument 'dat' in selecting a method for function 'confront': Problem with `filter()` input `..1`.
#> ℹ Input `..1` is `foo > 3`.
#> x object 'foo' not found
## When filter fails and pipes into mutate, however, we still
## get the same informative error we'd expect
iris %>%
filter(
foo > 3
) %>%
mutate(
bar = Sepal.Length + 1
)
#> Error: Problem with `filter()` input `..1`.
#> ℹ Input `..1` is `foo > 3`.
#> x object 'foo' not found Created on 2021-08-13 by the reprex package (v2.0.0) I'm not an expert of the codebase, but my suspicion from this error is that there's an S3 method for |
Also, FWIW, my mental model for what should happen here is that |
Ok, so I now understand your question better. The error:
is not thrown by > iris |> filter(foo>3) |> check_that(Sepal.Length>0)
Error in (function (cond) :
error in evaluating the argument 'dat' in selecting a method for function 'confront': Problem with `filter()` input `..1`.
ℹ Input `..1` is `foo > 3`.
✖ object 'foo' not found |
Thanks @markvanderloo. I think we're still getting our wires crossed. I know the error
is coming from
which is clearly coming from library(validate)
library(magrittr)
## Broken, but no dplyr
iris %>%
subset(
foo > 2
) %>%
check_that(
Sepal.Length < 100
)
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'dat' in selecting a method for function 'confront': object 'foo' not found
## Also broken, but no dplyr and no pipe
check_that(
subset(
iris,
foo > 2
),
Sepal.Length < 100
)
#> Error in h(simpleError(msg, call)): error in evaluating the argument 'dat' in selecting a method for function 'confront': object 'foo' not found
## Works fine
check_that(
subset(
iris,
Sepal.Length < 6
),
Sepal.Length < 100
)
#> Object of class 'validation'
#> Call:
#> check_that(subset(iris, Sepal.Length < 6), Sepal.Length < 100)
#>
#> Rules confronted: 1
#> With fails : 0
#> With missings: 0
#> Threw warning: 0
#> Threw error : 0 Created on 2021-08-15 by the reprex package (v2.0.1) What I'm saying is that I think that To reiterate from before: My mental model for what should happen in
I would expect subset(
subset(
iris,
foo > 2
),
Sepal.Length > 3
)
#> Error in eval(e, x, parent.frame()): object 'foo' not found Created on 2021-08-15 by the reprex package (v2.0.1) That's the kind of behavior I'd expect from Let me know if this doesn't clear up what I'm thinking |
Sorry in advance if this has already been asked -- I haven't seen anything about it. Pasting a
reprex
that does a better job explaining what's going on than I can:Created on 2021-08-13 by the reprex package (v2.0.0)
Basically,
filter
fails and thencheck_that
seems to not know what to do, so it spits out a bunch of junk before printing an actual error. This is a bigger issue when you chain 100 steps together though, because then it spits out too much junk to actually print / parse, so it's hard to figure out what's actually going wrong.Is this a known issue / conscious choice? And if it is, what's the best way to handle this behavior?
Thanks!
The text was updated successfully, but these errors were encountered: