tibble() should auto-splice unnamed tibble columns #581
I don't understand auto-splicing. Should anything change here:
library(rlang) library(tibble) quos <- quos(a = 5) tibble(!!!quos) #> # A tibble: 1 x 1 #> a #> <dbl> #> 1 5 tibble(quos) #> # A tibble: 1 x 1 #> quos #> <S3: quosures> #> 1 ~5
Created on 2019-02-22 by the reprex package (v0.2.1.9000)
The idea is that giving a name to a tibble namespaces it, i.e. creates a df-col. There were discussions about auto-splicing vs namespacing semantics in tidyverse/dplyr#3721, tidyverse/dplyr#4169 , tidyverse/dplyr#3967, and r-lib/tidyselect#86. I'll write a meta issue about it next week.
Implementation might be tricky. It involves turning off auto-labelling of quosures and manually labelling unnamed objects which are not tibbles at the right time. We now have
Auto-splicing doesn't use complicated syntax and doesn't have problems of evaluation timing.
It will be important to have auto-splicing in dplyr to implement
data %>% mutate( bar = bar(), mapping(starts_with("foo"), ~ .x / sd(.x)) )
If you splice,
I'm not yet convinced the principal constructor for data frames in the tidyverse is a low-risk environment ;-)
I'm especially concerned about the handling of name conflicts. Even if we apply tidyverse rules, this may lead to very surprising behavior.
To reiterate the argument:
Am I missing anything?
As an alternative, how about an auto-splicing adverb:
tibble(foo1 = 1:3, foo2 = 2:4, bar = 5) %>% mutate( bar = 6, auto_splice(tibble(foo1 = 2:4, foo2 = 3:5)) ) %>% flatten_auto_splice() ## tibble(foo1 = 2:4, foo2 = 3:5, bar = 6)