{"action":"closed","issue":{"url":"https://api.github.com/repos/hadley/dplyr/issues/1093","labels_url":"https://api.github.com/repos/hadley/dplyr/issues/1093/labels{/name}","comments_url":"https://api.github.com/repos/hadley/dplyr/issues/1093/comments","events_url":"https://api.github.com/repos/hadley/dplyr/issues/1093/events","html_url":"https://github.com/hadley/dplyr/issues/1093","id":69931742,"number":1093,"title":"data_frame(recycle(1:2),1:10) ?","user":{"login":"nicolasCoutin","id":6063192,"avatar_url":"https://avatars.githubusercontent.com/u/6063192?v=3","gravatar_id":"","url":"https://api.github.com/users/nicolasCoutin","html_url":"https://github.com/nicolasCoutin","followers_url":"https://api.github.com/users/nicolasCoutin/followers","following_url":"https://api.github.com/users/nicolasCoutin/following{/other_user}","gists_url":"https://api.github.com/users/nicolasCoutin/gists{/gist_id}","starred_url":"https://api.github.com/users/nicolasCoutin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nicolasCoutin/subscriptions","organizations_url":"https://api.github.com/users/nicolasCoutin/orgs","repos_url":"https://api.github.com/users/nicolasCoutin/repos","events_url":"https://api.github.com/users/nicolasCoutin/events{/privacy}","received_events_url":"https://api.github.com/users/nicolasCoutin/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-04-21T19:32:40Z","updated_at":"2015-05-19T15:32:57Z","closed_at":"2015-05-19T15:32:57Z","body":"What if `data_frame` had a convenience function `recycle()` to allow for recycling?\r\n\r\n```r\r\ndata_frame(recycle_aabb(1:2),1:10)    # equivalent to  rep(1:2, each = 5)\r\n# 1  1  1\r\n# 2  1  2\r\n# 3  1  3\r\n# 4  1  4\r\n# 5  1  5\r\n# 6  2  6\r\n# 7  2  7\r\n# 8  2  8\r\n# 9  2  9\r\n# 10 2 10\r\n```\r\n\r\n```r\r\ndata_frame(recycle_abab(1:2),1:10)    # equivalent to  rep(1:2, times = 5)  &  rep(1:2, length.out = 10)\r\n# 1  1  1\r\n# 2  2  2\r\n# 3  1  3\r\n# 4  2  4\r\n# 5  1  5\r\n# 6  2  6\r\n# 7  1  7\r\n# 8  2  8\r\n# 9  1  9\r\n# 10 2 10\r\n```\r\n\r\nThis would be very friendly to future me in terms of code readability. I don't have to remember what kind of `rep` call does what etc.. It's clear that I recycle by filling-in serially (`aabb`) or alternating (`abab`). I think of this as an analogous helper to `dplyr::desc()`.\r\n\r\nNow the cool bit is if it could be extendable to _any pattern_ you write after `recycle_`. That is if I could just write any pattern and it would just work:\r\n\r\n```r\r\ndata_frame(recycle_3a2b(1:2),1:10)    # equivalent to  rep(c(rep(1,3),rep(2,2)),2)\r\n# 1  1  1\r\n# 2  1  2\r\n# 3  1  3\r\n# 4  2  4\r\n# 5  2  5\r\n# 6  1  6\r\n# 7  1  7\r\n# 8  1  8\r\n# 9  2  9\r\n# 10 2 10\r\n```\r\n\r\nThis also means that you can check if the pattern makes sense relative to the maximum column length by factoring and throw an error if the pattern doesn't make sense otherwise it computes the result of recycling `1:2` with the `3a2b` pattern. I think this also generalizes to larger patterns: `3a2b1c7d9e`.\r\n\r\nWondering what @hadley & @romainfrancois think of this?\r\n\r\n\r\n"}}