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

Selecting -NULL #110

Closed
lionel- opened this issue Aug 21, 2019 · 7 comments
Closed

Selecting -NULL #110

lionel- opened this issue Aug 21, 2019 · 7 comments
Labels
dsl feature a feature request or enhancement

Comments

@lionel-
Copy link
Member

lionel- commented Aug 21, 2019

https://stackoverflow.com/questions/57590111/tidy-evaluation-adding-an-argument-to-a-function-that-prevents-gathering

@moodymudskipper

This comment has been minimized.

@lionel- lionel- added feature a feature request or enhancement dsl labels Sep 9, 2019
@hadley
Copy link
Member

hadley commented Sep 11, 2019

I'm not sure this is needed given that you can use integer():

tidyselect::vars_select(names(mtcars), integer())
#> named character(0)
tidyselect::vars_select(names(mtcars), -integer())
#>    mpg    cyl   disp     hp   drat     wt   qsec     vs     am   gear 
#>  "mpg"  "cyl" "disp"   "hp" "drat"   "wt" "qsec"   "vs"   "am" "gear" 
#>   carb 
#> "carb"

Created on 2019-09-11 by the reprex package (v0.3.0)

@lionel-
Copy link
Member Author

lionel- commented Sep 11, 2019

This would be nice for NULL defaults in function arguments. We have done similar changes elsewhere to make it easier to interface with NULL defaults (facets in ggplot IIRC).

@hadley
Copy link
Member

hadley commented Sep 11, 2019

I think making -NULL work is that way would be in conflict with tidyverse/design#24, and I don't think this case is compelling enough to violate the principle (given that there are two existing work arounds).

If we just want to solve the default value problem, I'd be in favour of:

nothing <- function() integer()

And adding a couple of tests to ensure that this behaviour is locked in.

@lionel-
Copy link
Member Author

lionel- commented Sep 11, 2019

I was thinking about the principle of treating NULL as an absent input.

Though I guess this principle would favour making this work actually:

vars_select(letters, -one_of(NULL))

Edit: hmm that wouldn't help OP since that's for character vectors, not quoted inputs.

@lionel-
Copy link
Member Author

lionel- commented Sep 12, 2019

I like nothing() but is it worth it to use up this symbol for such a corner case? Maybe it could also be used for teaching about vectors in R, e.g. letters[nothing()] creates a prototype.

Let's keep thinking about this, in the meantime I will recommend your solution of using integer() for default arguments. I'll also make one_of(NULL) be equivalent to one_of().

@hadley
Copy link
Member

hadley commented Sep 12, 2019

Sounds good to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dsl feature a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

3 participants