-
Notifications
You must be signed in to change notification settings - Fork 272
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
Inconsistent behaviour of map and pluck when indexing by name and location #1152
Comments
The purrr::map(x, list(2, "elt"))
#> [[1]]
#> [1] "foo"
#>
#> [[2]]
#> [1] "bar" |
It totally makes sense that Line 82 in 700ce19
If I make this mistake, others might as well? Maybe: #' # if you want to mix location and name indexing, use list
#' purrr::map_chr(x, list(2, "elt")) |
There is already an example similar to this. # Use a list to build an extractor that mixes numeric indices and names,
# and .default to provide a default value if the element does not exist
l2 |> map(list("num", 3))
#> [[1]]
#> [1] 3
#>
#> [[2]]
#> [1] 103
#>
#> [[3]]
#> NULL
#>
l2 |> map_int(list("num", 3), .default = NA)
#> [1] 3 103 NA |
Great! |
I was reading the
pluck
documentation when I stumbled on this interesting note in the examples:But when I wanted to try it, I got stuck. What my problem was is that mixing indexing by name and location does not work with
map()
, but I use it all the time withpluck
. Here is an example where I would expect the outcome of both map calls to be the same:Created on 2024-10-01 with reprex v2.1.1
Session info
The text was updated successfully, but these errors were encountered: