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

Meaningful error messages with options(warn = 2) #176

Open
bersbersbers opened this issue Mar 23, 2022 · 2 comments
Open

Meaningful error messages with options(warn = 2) #176

bersbersbers opened this issue Mar 23, 2022 · 2 comments

Comments

@bersbersbers
Copy link

Related to #122, this code fails:

options(warn = 2)
ggplot2::ggplot(data.frame(x = c(1, 2), y = c(1, 2), show = c(TRUE, FALSE)), ggplot2::aes(x = x, y = y)) +
    ggplot2::geom_point() +
    gghighlight::gghighlight(show)

Error in ggplot_add():
! All calculations failed! Please provide a valid predicate.
Backtrace:
1. ggplot2:::+.gg(...)
2. ggplot2:::add_ggplot(e1, e2, e2name)
4. gghighlight:::ggplot_add.gg_highlighter(object, p, objectname)

This is a quite opaque error message, as the computations fail only because an internal warning was converted into an error, and not because the the computation itself failed. Thus, if options(warn = 2) is set (or generally), it might make sense to check if the thrown error is a converted warning, in which case one might rethrow the original error instead of consuming it.

@yutannihilation
Copy link
Owner

Thanks for reporting, but if I remember correctly, this is difficult. Due to a design decision to support both grouped and non-grouped predicates, gghighlight needs to ignore errors. I agree this is technically possible, but I think I found propagating errors was a tough job.

@bersbersbers
Copy link
Author

I see. Well, now that #177 is fixed, this issue is certainly less urgent.

Otherwise, one might wrap the internal computations in some withr::with_options(warn=min(1, options()$warn)) or similar to soften the effect of external options(warn = 2).

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

2 participants