-
Notifications
You must be signed in to change notification settings - Fork 275
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
map_* expects a vector of length 1 #518
Comments
For example, I really expect this to work: l1 <- list(list(a = 1L),
list(a = c(1L, 2L, 3L)))
purrr::map_int(l1, "a")
#> Error: Result 2 is not a length 1 atomic vector
purrr::map_chr(l1, function(x){class(x$a)})
#> [1] "integer" "integer" |
In terms of getting what you want, library(purrr)
l1 <- list(list(a = 1L),
list(a = c(1L, 2L, 3L)))
map(l1, "a") %>% flatten_int()
#> [1] 1 1 2 3 |
Fair enough, but the reason for the issue (and pull request) is that the
documentation doesn't make this clear.
The documentation seems to imply that the initial example should be
possible.
How can we change the documentation so that it is clearer the ??
…On Wed, Jun 20, 2018, 4:29 PM Jennifer (Jenny) Bryan < ***@***.***> wrote:
In terms of getting what you want, map() followed by a type-specific
flatten_*() does it:
library(purrr)
l1 <- list(list(a = 1L),
list(a = c(1L, 2L, 3L)))
map(l1, "a") %>% flatten_int()#> [1] 1 1 2 3
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#518 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABcI-iDmphtAmyDyoK_jWFwUkp8CnLKFks5t-rCXgaJpZM4Uv5wT>
.
|
@rmflight I hope I am not adding noise to the discussion, but what about the first line of the description of the map functions?:
Does this not imply that the function to be mapped by |
I proposed some wording in the PR: #517 (comment) |
Not about the wording but for reference about the use case needing flatten after map, there is an open PR #502 adding # devtools::install_github("tidyverse/purrr#502)
library(purrr)
l1 <- list(list(a = 1L),
list(a = c(1L, 2L, 3L)))
map_flat_int(l1, "a")
#> [1] 1 1 2 3 Created on 2018-06-21 by the reprex package (v0.2.0). |
This isn't really documented in the
map_*
that these functions expect a length 1 vector.It is disconcerting, b/c the
map_df*
functions don't care how big the resulting objects are, they just get merged together.Small pull request to update the documentation.
The text was updated successfully, but these errors were encountered: