-
Notifications
You must be signed in to change notification settings - Fork 130
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
tibble() should auto-splice unnamed tibble columns #581
Comments
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 |
|
I feel compelled to mention that having shape or type depend on the presence/absence of names has felt awkward in the past. I think that comes up in the long-running |
This feels awkward. Users can always splice manually. What's the advantage of auto-splicing? Thinking about namespaces in C++: an unnamed namespace is still a namespace and doesn't somehow get embedded into its parent. Auto-named tibble columns feel similar. |
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, |
And we're trying it out with |
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)
|
An We have already started using the named/unnamed syntax in |
It is low risk because I find it very hard to imagine that anyone is counting on the current behaviour: library(tibble)
names(tibble(tibble(x = 1, y = 2)))
#> [1] "tibble(x = 1, y = 2)" Created on 2019-07-01 by the reprex package (v0.3.0) |
There's also: names(tibble::tibble(mtcars))
#> [1] "mtcars" Created on 2019-08-07 by the reprex package (v0.3.0) Are we still considering auto-splice? I'm happy to implement, just double-checking. |
This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary. |
For compatibility with proposed dplyr semantics
cc @lionel-
The text was updated successfully, but these errors were encountered: