You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When passing variable names as string, is seems natural to have optional arguments default to NULL.
However, this makes it difficult to use data_syms(), as it cannot convert these.
library(rlang)
f<-function(df, a=NULL, b=NULL) {
syms<- data_syms(list(a=a, b=b))
vctrs::data_frame(!!!lapply(syms, eval_tidy, data=df))
}
mtcars|> f("cyl", "disp") |> head()
#> a b#> 1 6 160#> 2 6 160#> 3 4 108#> 4 6 258#> 5 8 360#> 6 6 225# Here, we only want the `a` columnmtcars|> f("cyl") |> head()
#> Error in `sym()`:#> ! Can't convert `NULL` to a symbol.
hmm I don't know. It seems like it's better to be explicit at the call site by calling compact() before data_syms(), that will make it very clear what's going on and is still quite terse.
Thanks for the response Lionel. I think we'd like to preserve NULL rather than filter out NULL-elements. From ggplot2's end, geom_point(mapping = aes(colour = NULL)) negates a global mapping in ggplot(mapping = aes(colour = foo)). I think this is useful behaviour to carry over.
When passing variable names as string, is seems natural to have optional arguments default to
NULL
.However, this makes it difficult to use
data_syms()
, as it cannot convert these.Created on 2024-12-09 with reprex v2.1.1
My proposal is to make it easy to have
data_syms(list(NULL))
returnlist(NULL)
.For context, this is related to tidyverse/ggplot2#6208.
The text was updated successfully, but these errors were encountered: