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

Improve error messages about conflicted parameters #2854

Conversation

yutannihilation
Copy link
Member

This is suggested in #2761 (comment).

The current error messages are like:

Specify either position or nudge_x/nudge_y

@clauswilke's suggestion is:

position and width/height cannot both be specified. Please specify only one

I feel the latter follows the tidyverse style of error messages; it consists of "problem statement" + "hint".

@hadley
Copy link
Member

hadley commented Aug 24, 2018

I think you can use "must" here: "You must specify one of position and width/height".

Also for nudging error, I think it would be worthwhile to extract the repeated code into a function like check_nudge_specification()

@yutannihilation
Copy link
Member Author

Thanks, I agree with you on both.

@yutannihilation
Copy link
Member Author

For check_nudge_specification(), I feel a bit afraid that I have to scratch my head to figure out how to pass missingness. Let me think a bit more...

@hadley
Copy link
Member

hadley commented Aug 24, 2018

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
package
(v0.2.0).

@yutannihilation
Copy link
Member Author

Sorry, I can't come up with any better way; in this case, we cannot use waiver() for position, since default of position must be a valid name of an existing Position class.

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.

@clauswilke
Copy link
Member

This looks fine to me. @hadley, do you have any more concerns? Otherwise we should include it in the 3.0.1 release also.

@hadley
Copy link
Member

hadley commented Sep 14, 2018

@batpigandme can you suggest any improvements to the phrasing here?

@clauswilke
Copy link
Member

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."

@clauswilke clauswilke mentioned this pull request Sep 14, 2018
25 tasks
@clauswilke
Copy link
Member

@batpigandme Just a friendly reminder: Could you look over the proposed error messages and either approve or suggest alternative wording? Thanks!

@batpigandme
Copy link
Contributor

Thanks @clauswilke, I'd totally missed this. How about:

#> You must specify either `var 1` or `var 2`

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)
Copy link
Contributor

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"?

Copy link
Member

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.

Copy link
Contributor

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.

Copy link
Member

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)
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aw, sorry...

@yutannihilation
Copy link
Member Author

Thanks for suggestion, @batpigandme. I updated the text.

@clauswilke
Copy link
Member

Thanks!

@clauswilke clauswilke merged commit fa3cd8f into tidyverse:master Sep 18, 2018
@yutannihilation yutannihilation deleted the improve-error-about-conflicted-param branch September 18, 2018 02:46
@lock
Copy link

lock bot commented Mar 17, 2019

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/

@lock lock bot locked and limited conversation to collaborators Mar 17, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants