-
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
automatically name unnamed pluckers in hoist #837
Comments
This is an interesting idea. What would you do if the pluck spec is a number? Or the number comes first? |
maybe there should be a short and a long name option, e.g. something like
as the numbers in a spec will probably be small one might also use words for the, i.e. |
That's starting to feel a bit too magical too me — I think there'd have to be one principle applied consistently. |
Looking at it again I agree that it looks quite magical. One easy principle would be to simply use For short names one would use basically the same strategy but keep all trailing numbers, i.e. Do you like that better? |
The case that seems like a no-brainer and a great place to start is when you pluck a string. That covers so much of the pain IMO. This is the case where I most feel like That being said, I feel like we discussed this once in slack @hadley, and you objected? There is some potential for muddying the waters re: our quoting conventions. library(tidyverse)
#> Warning: package 'tibble' was built under R version 3.6.2
df <- tibble(
character = c("Toothless", "Dory"),
metadata = list(
list(
species = "dragon",
color = "black",
films = c(
"How to Train Your Dragon",
"How to Train Your Dragon 2",
"How to Train Your Dragon: The Hidden World"
)
),
list(
species = "blue tang",
color = "blue",
films = c("Finding Nemo", "Finding Dory")
)
)
)
df %>%
hoist(metadata, species = "species", color = "color")
#> # A tibble: 2 x 4
#> character species color metadata
#> <chr> <chr> <chr> <list>
#> 1 Toothless dragon black <named list [1]>
#> 2 Dory blue tang blue <named list [1]> Created on 2020-04-03 by the reprex package (v0.3.0.9001) |
Ok, let's start with just naming single string pluckers. |
Often one wants to name the columns produced by
hoist()
the same as the element in the list. So to makehoist()
less verbose and more comfortable for interactive use I propose automatically naming the column as follows for unnamed arguments:list("film", 1)
would produce the column namefilm_1
.The text was updated successfully, but these errors were encountered: