-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Improve error message when plot.title.position
is not correctly mentioned.
#5296
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
Conversation
Hi there, Good catch on these errors that are formatted confusingly. library(rlang)
title_pos <- "wrong input"
arg_match0(
title_pos, c("panel", "plot"),
arg_nm = "plot.title.position",
error_call = expr(theme())
)
#> Error in `theme()`:
#> ! `plot.title.position` must be one of "panel" or "plot", not "wrong
#> input".
#> Backtrace:
#> ▆
#> 1. ├─rlang::arg_match0(...)
#> 2. └─rlang:::stop_arg_match(w, values = x, error_arg = y, error_call = z)
#> 3. └─rlang::abort(msg, call = error_call, arg = error_arg) Created on 2023-05-03 with reprex v2.0.2 |
Hi, Thanks for the suggestion. Would you like me to update my PR and snapshots with this instead? # new
arg_match0(
title_pos, c("panel", "plot"),
arg_nm = "plot.title.position",
error_call = expr(theme())
)
# delete
if (!(title_pos %in% c("panel", "plot"))) {
cli::cli_abort("{.var plot.title.position} should be either {.val panel} or {.val plot}.")
} |
That'd be great, thanks! |
Just a note, globally, this part of the error message ggplot(mtcars) + geom_point(aes(disp, mpg)) + theme(plot.title.position = "test")
Error in `theme()`:
! `plot.title.position` must be one of "panel" or "plot", not
"test". It is the new error message. but I tried another thing for example with plot.background. ggplot() + theme(plot.background = "w")
Error in `mapply()`
! The `plot.background` theme element must be a <element_rect>
object. Edit: the |
Yes I think ggplot2 could do a little bit better in reporting where the error has originated sometimes. To be fair, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me
I think the failing test on R devel is unrelated to this PR. From the R news section:
Which causes @olivroy Thanks for the work you've put into this PR! |
Before this PR
With this PR
I wonder how we could better improve this message, so it becomes:
But I don't know how to do that.
Edit: I added suggestion to use
rlang::arg_match()
to get rid of theif ()
, but this doesn't solve the error call.