-
Notifications
You must be signed in to change notification settings - Fork 416
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
Better naming options for pack() #795
Comments
Slightly more straightforward reprex: library(tidyr)
iris %>%
as_tibble() %>%
pack(Sepal = starts_with("Sepal"), Petal = starts_with("Petal"))
#> # A tibble: 150 x 3
#> Species Sepal$Sepal.Length $Sepal.Width Petal$Petal.Length $Petal.Width
#> <fct> <dbl> <dbl> <dbl> <dbl>
#> 1 setosa 5.1 3.5 1.4 0.2
#> 2 setosa 4.9 3 1.4 0.2
#> 3 setosa 4.7 3.2 1.3 0.2
#> 4 setosa 4.6 3.1 1.5 0.2
#> 5 setosa 5 3.6 1.4 0.2
#> 6 setosa 5.4 3.9 1.7 0.4
#> 7 setosa 4.6 3.4 1.4 0.3
#> 8 setosa 5 3.4 1.5 0.2
#> 9 setosa 4.4 2.9 1.4 0.2
#> 10 setosa 4.9 3.1 1.5 0.1
#> # … with 140 more rows Created on 2019-11-24 by the reprex package (v0.3.0) Maybe this could be achieved by iris %>%
as_tibble() %>%
pack(
Sepal = starts_with("Sepal"),
Petal = starts_with("Petal"),
.names_sep = "."
) Since you'd still want some way to strip the |
One suggestion is a
Although I note a couple of issues:
Another approach would extend Hadley's:
To this:
So the
The
|
I like the idea of pack and unpack, especially as they sometimes come quite natural when working with JSON data from APIs. In such a case I might want to unpack a tibble column, manipulate it and pack it afterwards again. E.g.
Created on 2019-10-30 by the reprex package (v0.3.0)
Unfortunately, this repacking step isn't supported very nicely as I cannot change the names in the step of packing. I would imagine something along the following lines to be possible:
The first case is especially confusing as the names are simply ignored without a warning.
The text was updated successfully, but these errors were encountered: