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
export magrittr::extract()? #223
Comments
:) That may just be because they are not used to it. Once you get the hang of mapping operators you can do stuff like this:
|
That's true. My own horror at this has now faded to a distant memory. I think it catches attention because many people don't predict that using a vector as
Also in a past email conversation, there was talk of a select method for lists. Reminding you of a relevant example you wrote: library(purrr)
library(dplyr)
x <- rerun(2, head(mtcars,2))
x %>% map_df(select, cyl, am)
#> cyl am
#> 1 6 1
#> 2 6 1
#> 3 6 1
#> 4 6 1 |
|
I'd rather fix this by improving the documentation for |
|
I never really thought this would fly but just want to point out this issue was about retrieving "multiple elements at the same level of the list hierarchy". So, more like |
|
Oh gotcha. I think an explicit |
|
The issue with explicit > purrr::map_dfr(x, ~list(two = purrr::pluck(.x, "two", .default = NA),
three = purrr::pluck(.x, "three", .default = NA)))
#> or
> purrr::map_dfr(x, function(i) purrr::map(purrr::set_names(c("two", "three")),
~purrr::pluck(i, .x, .default = NA)))
#> A tibble: 2 x 2
#> two three
#> <chr> <dbl>
#>1 three 4.00
#>2 seven 8.00Or, what I usually need for creating list-columns: > purrr::map(x, ~tibble::tibble(two=purrr::pluck(.x, "two", .default = NA),
three=purrr::pluck(.x, "three", .default = NA)))
#> or
> purrr::map(x, function(i) purrr::map_dfr(purrr::set_names(c("two", "three")),
~purrr::pluck(i, .x, .default = NA)))
#> [[1]]
#> # A tibble: 1 x 2
#> two three
#> <chr> <dbl>
#> 1 three 4.00
#>
#> [[2]]
#> # A tibble: 1 x 2
#> two three
#> <chr> <dbl>
#> 1 seven 8.00 |
|
@dmi3kno since this issue was closed over a year ago, commenting here is pretty low-visibility. If you could please open a new issue that refers back to this with your reprex etc., it will be much easier for the maintainers to find it. Thanks |
I taught
purrrtoday. We selected multiple elements at the same level of the list hierarchy. Overall reaction was "elegant and simplifying", but mapping[was described as "ugly and horrifying".Is there any chance of re-exporting
magrittr::extract()?The text was updated successfully, but these errors were encountered: