- Notifications
You must be signed in to change notification settings - Fork2.1k
Vignette: discuss optional string input#6215
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Conversation
yjunechoe commentedDec 5, 2024
Tangentially related, but I wonder whether rlang::data_sym(NULL)#> NULL Instead of its current behavior: rlang::data_sym(NULL)#> Error in `sym()`:#> ! Can't convert `NULL` to a symbol. Especially because I feel like this "optional character-input" problem has already been solved in tidyselect (with df<-data.frame(x=1)# Tidyselect behaviortidyselect_get<-function(df,col) {tidyselect::eval_select(tidyselect::all_of(col),df)}tidyselect_get(df,"x")#> x#> 1tidyselect_get(df,NULL)#> named integer(0)# Tidyeval with `data_sym()`tidyeval_get<-function(df,col) {rlang::eval_tidy(rlang::data_sym(col),df)}tidyeval_get(df,"x")#> [1] 1tidyeval_get(df,NULL)#> Error in `sym()`:#> ! Can't convert `NULL` to a symbol.# Tidyeval with modified `data_sym2()` that passes NULL throughdata_sym2<- \(x)if (!is.null(x))rlang::data_sym(x)tidyeval_get2<-function(df,col) {rlang::eval_tidy(data_sym2(col),df)}tidyeval_get2(df,"x")#> [1] 1tidyeval_get2(df,NULL)#> NULL |
teunbrand commentedDec 5, 2024
Thanks June, your comments make a lot of sense to me. I'd agree that this having |
yjunechoe commentedDec 5, 2024
Yeah, that's the intended build-up of my comment! Would be nice for the FR to be backed by a need in ggplot 😄 |
thomasp85 commentedDec 4, 2025
I'm personally partial to advocating embrace for people wanting to build ggplot2 wrapper functions. The issue noted in the original issue (name of column coming as a string) is easily solved: plot_embrace<-function(dat,xvar,yvar,colorvar=NULL,shapevar=NULL) {myplot<- ggplot(dat,aes(x={{xvar }},y={{yvar }},color={{colorvar }},shape={{shapevar }}))+ geom_point()return(myplot)}whichvar<- sample(c('sex','employment'),1)plot_embrace(plotdat,weight,height,colorvar=age,shapevar=!!sym(whichvar)) |
teunbrand commentedDec 4, 2025
I'm happy to recommend the |
This PR aims tofix#6208.
If somebody has better advice for dealing with optional character-input, I'd be glad to adjust.