Skip to content
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

pmap returns output length zero if at least one element is length 0 #695

Closed
benjaminschwetz opened this issue Jul 31, 2019 · 2 comments
Closed
Labels
bug an unexpected problem or unintended behavior map 🗺️

Comments

@benjaminschwetz
Copy link

benjaminschwetz commented Jul 31, 2019

Edit: related to #679

Regarding inputs of length 0, the documentation for pmap() / map2() states under values:

If all input is length 0, the output will be length 0.

I deducted from this statement that the output would not be length zero, if all inputs would not be 0. I.e. NULLs would be passed on to the functions together with the other elements. However, if I pass a list with at least one element of length 0, to pmap(), the output is length 0.

l <- list(letters, LETTERS, NULL)
x <- purrr::pmap(l,c)
x
#> list()
#What I would expect x to look like:
list(
  c(letters[1], LETTERS[1], NULL),
  c(letters[2], LETTERS[2], NULL),
  c(letters[3], LETTERS[3], NULL)
  # etc.
)
#> [[1]]
#> [1] "a" "A"
#> 
#> [[2]]
#> [1] "b" "B"
#> 
#> [[3]]
#> [1] "c" "C"

Created on 2019-07-31 by the reprex package (v0.3.0)

@lionel-
Copy link
Member

lionel- commented Oct 15, 2019

In the future this will probably become an error. We have adopted the rule that only length 1 vectors can be recycled. See discussion in tidyverse/design#13

@lionel- lionel- added bug an unexpected problem or unintended behavior pmap 🗺️ labels Jan 20, 2020
@hadley
Copy link
Member

hadley commented Aug 27, 2022

Now duplicate of #878

@hadley hadley closed this as completed Aug 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior map 🗺️
Projects
None yet
Development

No branches or pull requests

3 participants