{"action":"created","issue":{"url":"https://api.github.com/repos/hadley/purrr/issues/179","repository_url":"https://api.github.com/repos/hadley/purrr","labels_url":"https://api.github.com/repos/hadley/purrr/issues/179/labels{/name}","comments_url":"https://api.github.com/repos/hadley/purrr/issues/179/comments","events_url":"https://api.github.com/repos/hadley/purrr/issues/179/events","html_url":"https://github.com/hadley/purrr/issues/179","id":136320818,"number":179,"title":"map_df fails on mapping functions that generate single rows","user":{"login":"jebyrnes","id":757410,"avatar_url":"https://avatars.githubusercontent.com/u/757410?v=3","gravatar_id":"","url":"https://api.github.com/users/jebyrnes","html_url":"https://github.com/jebyrnes","followers_url":"https://api.github.com/users/jebyrnes/followers","following_url":"https://api.github.com/users/jebyrnes/following{/other_user}","gists_url":"https://api.github.com/users/jebyrnes/gists{/gist_id}","starred_url":"https://api.github.com/users/jebyrnes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jebyrnes/subscriptions","organizations_url":"https://api.github.com/users/jebyrnes/orgs","repos_url":"https://api.github.com/users/jebyrnes/repos","events_url":"https://api.github.com/users/jebyrnes/events{/privacy}","received_events_url":"https://api.github.com/users/jebyrnes/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":10,"created_at":"2016-02-25T08:50:43Z","updated_at":"2016-02-29T16:29:34Z","closed_at":"2016-02-29T11:21:00Z","body":"If a map function creates a single row of output, map_df will fail in making a data frame. One can force it to work by making a data frame of the transpose of the output, but that seems like an unnecessary PITA.\r\n\r\nWhile there may be a different function to use, this strikes me as behavior that is not quite sensible.\r\n\r\nExample:\r\n\r\nalist <- list(\r\n  data.frame(a=1:10, b=1:10),\r\n  data.frame(a=21:30, b=31:40)\r\n\r\n)\r\n\r\n#returns normally\r\nmap_df(alist, .f = function(x) x+1)\r\n\r\n#returns Error: cannot convert object to a data frame\r\nmap_df(alist, .f = colMeans)\r\n\r\n#returns with the proper output\r\nmap_df(alist, function(x) data.frame(t(colMeans(x))))\r\n"},"comment":{"url":"https://api.github.com/repos/hadley/purrr/issues/comments/190277872","html_url":"https://github.com/hadley/purrr/issues/179#issuecomment-190277872","issue_url":"https://api.github.com/repos/hadley/purrr/issues/179","id":190277872,"user":{"login":"jennybc","id":599454,"avatar_url":"https://avatars.githubusercontent.com/u/599454?v=3","gravatar_id":"","url":"https://api.github.com/users/jennybc","html_url":"https://github.com/jennybc","followers_url":"https://api.github.com/users/jennybc/followers","following_url":"https://api.github.com/users/jennybc/following{/other_user}","gists_url":"https://api.github.com/users/jennybc/gists{/gist_id}","starred_url":"https://api.github.com/users/jennybc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jennybc/subscriptions","organizations_url":"https://api.github.com/users/jennybc/orgs","repos_url":"https://api.github.com/users/jennybc/repos","events_url":"https://api.github.com/users/jennybc/events{/privacy}","received_events_url":"https://api.github.com/users/jennybc/received_events","type":"User","site_admin":false},"created_at":"2016-02-29T16:29:34Z","updated_at":"2016-02-29T16:29:34Z","body":"This is educational! I feel like I still struggle with row binding with `dplyr` + `purrr` in situations where `plyr` makes it easy to express myself.\r\n\r\n@lionel-  How would you do this with `purrr`?\r\n\r\n``` r\r\nx <- dplyr::data_frame(int = 1:3,\r\n                       let = letters[int],\r\n                       fac = factor(let),\r\n                       dbl = int + 0.1)\r\nplyr::ldply(x, class, .id = \"var_name\")\r\n#>   var_name        V1\r\n#> 1      int   integer\r\n#> 2      let character\r\n#> 3      fac    factor\r\n#> 4      dbl   numeric\r\n```"}}