-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Improve error messages about conflicted parameters #2854
Improve error messages about conflicted parameters #2854
Conversation
I think you can use "must" here: "You must specify one of Also for nudging error, I think it would be worthwhile to extract the repeated code into a function like |
Thanks, I agree with you on both. |
For |
Oh yeah, I always forget about that. In that case, don't worry about a function. f <- function(x, y = NULL) {
g(x, y)
}
g <- function(x, y) {
c(x = missing(x), y = missing(y))
}
f()
#> x y
#> TRUE FALSE
f(1, 2)
#> x y
#> FALSE FALSE Created on 2018-08-24 by the reprex |
Sorry, I can't come up with any better way; in this case, we cannot use I hope duplication of the error message will be resolved by the new error system which will be introduced i rlang 0.3.0. So, I want to give up a function for now. |
This looks fine to me. @hadley, do you have any more concerns? Otherwise we should include it in the 3.0.1 release also. |
@batpigandme can you suggest any improvements to the phrasing here? |
My preference would be to be a bit more specific about the exclusive nature of the constraint. E.g., instead of writing "you must specify one", I would write "you must specify at most one" or "you must specify exactly one" or "you must specify only one". Or, something along the lines of "You cannot specify both ... at the same time. You must specify only one." |
@batpigandme Just a friendly reminder: Could you look over the proposed error messages and either approve or suggest alternative wording? Thanks! |
Thanks @clauswilke, I'd totally missed this. How about:
|
R/geom-jitter.r
Outdated
@@ -39,7 +39,7 @@ geom_jitter <- function(mapping = NULL, data = NULL, | |||
inherit.aes = TRUE) { | |||
if (!missing(width) || !missing(height)) { | |||
if (!missing(position)) { | |||
stop("Specify either `position` or `width`/`height`", call. = FALSE) | |||
stop("You must specify one of `position` and `width`/`height`", call. = FALSE) |
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.
Proposed mashup of old/new:
"You must specify either position
or width
/height
"?
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.
Would it be terrible to add "but not both"? The reason why I started this conversation in the first place was that I felt the error message didn't sufficiently clearly express that the error is that both options are specified at once.
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.
I think the either...or
construct provides that.
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.
Ok.
@yutannihilation Would you mind updating the error text to what @batpigandme proposed, and then I'll merge?
R/geom-label.R
Outdated
@@ -17,7 +17,7 @@ geom_label <- function(mapping = NULL, data = NULL, | |||
inherit.aes = TRUE) { | |||
if (!missing(nudge_x) || !missing(nudge_y)) { | |||
if (!missing(position)) { | |||
stop("Specify either `position` or `nudge_x`/`nudge_y`", call. = FALSE) | |||
stop("You must specify either `position` or `nudge_x`/`nudge_y`", call. = FALSE) |
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.
I think this one is still missing a period.
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.
Aw, sorry...
Thanks for suggestion, @batpigandme. I updated the text. |
Thanks! |
This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/ |
This is suggested in #2761 (comment).
The current error messages are like:
@clauswilke's suggestion is:
I feel the latter follows the tidyverse style of error messages; it consists of "problem statement" + "hint".