{"action":"created","issue":{"url":"https://api.github.com/repos/hadley/purrr/issues/64","labels_url":"https://api.github.com/repos/hadley/purrr/issues/64/labels{/name}","comments_url":"https://api.github.com/repos/hadley/purrr/issues/64/comments","events_url":"https://api.github.com/repos/hadley/purrr/issues/64/events","html_url":"https://github.com/hadley/purrr/issues/64","id":68977843,"number":64,"title":"Inconsistent behavior with map ~ lapply, and map_n ~ Map","user":{"login":"jonboiser","id":10248067,"avatar_url":"https://avatars.githubusercontent.com/u/10248067?v=3","gravatar_id":"","url":"https://api.github.com/users/jonboiser","html_url":"https://github.com/jonboiser","followers_url":"https://api.github.com/users/jonboiser/followers","following_url":"https://api.github.com/users/jonboiser/following{/other_user}","gists_url":"https://api.github.com/users/jonboiser/gists{/gist_id}","starred_url":"https://api.github.com/users/jonboiser/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jonboiser/subscriptions","organizations_url":"https://api.github.com/users/jonboiser/orgs","repos_url":"https://api.github.com/users/jonboiser/repos","events_url":"https://api.github.com/users/jonboiser/events{/privacy}","received_events_url":"https://api.github.com/users/jonboiser/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-04-16T18:00:36Z","updated_at":"2015-04-22T21:52:29Z","closed_at":null,"body":"In the package, `map` seems to wrap `lapply`, while `map_n` wraps `Map`, which leads to different behavior. \r\n\r\nFor me, the thing that I noticed is that if your input to `map_n` is a character vector, your output is a named list whose names are that character vector. Whereas with plain `map`, it's an unnamed list.\r\n\r\n```r\r\ninput <- letters[1:5]\r\nmap(input, function(x) 1) %>% names #=> NULL\r\nmap_n(list(input), function(x) 1) %>% names #=> \"a\", \"b\", \"c\", \"d\", \"e\"\r\n```\r\n\r\nBefore I noticed this, I would have to insert the names using `magrittr::set_names` or `names<-`.\r\n\r\nFor my own purposes, I actually prefer having the names automatically inserted, so I would just use `map_n` by default from now on."},"comment":{"url":"https://api.github.com/repos/hadley/purrr/issues/comments/95350058","html_url":"https://github.com/hadley/purrr/issues/64#issuecomment-95350058","issue_url":"https://api.github.com/repos/hadley/purrr/issues/64","id":95350058,"user":{"login":"lionel-","id":4465050,"avatar_url":"https://avatars.githubusercontent.com/u/4465050?v=3","gravatar_id":"","url":"https://api.github.com/users/lionel-","html_url":"https://github.com/lionel-","followers_url":"https://api.github.com/users/lionel-/followers","following_url":"https://api.github.com/users/lionel-/following{/other_user}","gists_url":"https://api.github.com/users/lionel-/gists{/gist_id}","starred_url":"https://api.github.com/users/lionel-/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lionel-/subscriptions","organizations_url":"https://api.github.com/users/lionel-/orgs","repos_url":"https://api.github.com/users/lionel-/repos","events_url":"https://api.github.com/users/lionel-/events{/privacy}","received_events_url":"https://api.github.com/users/lionel-/received_events","type":"User","site_admin":false},"created_at":"2015-04-22T21:52:29Z","updated_at":"2015-04-22T21:52:29Z","body":"`map()` and `lapply()` have consistent behavior because they always use the names of the input list or vector to name the output. For example, this will work:\r\n```r\r\nletters[1:5] %>% setNames(., .) %>% map(function(x) 1)\r\n```\r\n\r\nOn the other hand, `Map()` behavior is not so consistent because it only names the output after the input elements if the input is an unnamed character vector. So, if your input vector happens to have names, or to be any other type than a character vector, `Map()` will not recycle the elements into names."}}