-
Notifications
You must be signed in to change notification settings - Fork 418
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
pack() / unpack() #523
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Random things:
|
I guess this would be data %>% pack(
x = vars(...),
y = nesting(vars(...))
)
How about copying them inside the nested df? It sounds useful to carry them around. |
vars() sounds good, otherwise maybe pick(), pick_if(), pick_at(), ... |
I’m not sure i get the nesting() thing. We would need to make a list column of n() row 1 tibbles ? |
Yes, which is occasionally useful. Not that important, I just thought maybe the interfaces could be made consistent, in case we include |
I propose we keep @romainfrancois simple syntax for |
I think library(dplyr, warn.conflicts = FALSE)
as_tibble(iris) %>%
select(Sepal = starts_with("Sepal"),
Petal = starts_with("Petal"))
#> # A tibble: 150 x 4
#> Sepal1 Sepal2 Petal1 Petal2
#> <dbl> <dbl> <dbl> <dbl>
#> 1 5.1 3.5 1.4 0.2
#> 2 4.9 3 1.4 0.2
#> 3 4.7 3.2 1.3 0.2
#> 4 4.6 3.1 1.5 0.2
#> 5 5 3.6 1.4 0.2
#> 6 5.4 3.9 1.7 0.4
#> 7 4.6 3.4 1.4 0.3
#> 8 5 3.4 1.5 0.2
#> 9 4.4 2.9 1.4 0.2
#> 10 4.9 3.1 1.5 0.1
#> # … with 140 more rows Created on 2019-02-08 by the reprex package (v0.2.1.9000) On the other hand, I expect # c.f. https://github.com/yutannihilation/tiedr#auto_bundle
d <- tibble::tribble(
~A_a_x, ~A_a_y, ~A_b_x, ~B_a_x, ~B_b_x, ~B_b_y,
1, 2, 3, 4, 5, 6,
2, 3, 4, 5, 6, 7
)
d %>%
pack(
A = list(
a = list(x = A_a_x, y = A_a_y),
b = list(x = A_b_x)
),
B = list(
a = list(x = B_a_x),
b = list(x = B_b_x, y = B_b_y),
)
) Of course, the users don't write this by hand. Probably some helper functions or higher interfaces are needed. For example, the code above should be written as something like: # something like `seperate()` for colnames
spec <- guess_structure_from_colnames(d, sep = "_")
d %>%
pack(!!!spec) So, I agree the syntax of (Sorry, I didn't notice this issue at the time of writing this post... I should have mentioned this issue!) |
(@yutannihilation FWIW I'm leaning towards "packed" columns rather than "bundled" columns because |
Alternatively, if we had packed <- iris %>%
tibble() %>%
morph(petal = sels(starts_with("Petal")), sepal = sels(starts_with("Sepal")))
unpacked <- packed %>%
morph(petal, sepal) And @yutannihilation's more complicated nested structure becomes: d %>%
morph(
A = tibble(
a = tibble(x = A_a_x, y = A_a_y),
b = tibble(x = A_b_x)
),
B = tibble(
a = tibble(x = B_a_x),
b = tibble(x = B_b_x, y = B_b_y),
)
) This also has the nice property that |
But given how much stuff we already have schedule for 0.9.0, |
Thanks, I don't mind. "Bundle" was just needed to write one blog post. I didn't intend to advertise the term itself. I'll use "pack" next time 👍 Using |
You'll also have something like a data %>% morph(df_col = sels(starts_with("d")) I realised yesterday that unpacking with data %>% morph(packed = tibble(foo, bar)) %>% morph(packed) Because unnamed tibbles will be automatically spliced. |
Is the idea that df <- tibble(x=1:3,y=tibble(a=1:3,b=1:3),z=4:6)
colnames(df)
colnames(jsonlite::flatten(df)) |
(very sketchy, just unloading pack from my head)
Created on 2018-12-13 by the reprex package (v0.2.1.9000)
The text was updated successfully, but these errors were encountered: