Skip to content

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

@bersbersbers

Description

@bersbersbers

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions