{"action":"created","issue":{"url":"https://api.github.com/repos/hadley/purrr/issues/221","repository_url":"https://api.github.com/repos/hadley/purrr","labels_url":"https://api.github.com/repos/hadley/purrr/issues/221/labels{/name}","comments_url":"https://api.github.com/repos/hadley/purrr/issues/221/comments","events_url":"https://api.github.com/repos/hadley/purrr/issues/221/events","html_url":"https://github.com/hadley/purrr/pull/221","id":170283063,"number":221,"title":"Added create_env","user":{"login":"kendonB","id":5327505,"avatar_url":"https://avatars.githubusercontent.com/u/5327505?v=3","gravatar_id":"","url":"https://api.github.com/users/kendonB","html_url":"https://github.com/kendonB","followers_url":"https://api.github.com/users/kendonB/followers","following_url":"https://api.github.com/users/kendonB/following{/other_user}","gists_url":"https://api.github.com/users/kendonB/gists{/gist_id}","starred_url":"https://api.github.com/users/kendonB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kendonB/subscriptions","organizations_url":"https://api.github.com/users/kendonB/orgs","repos_url":"https://api.github.com/users/kendonB/repos","events_url":"https://api.github.com/users/kendonB/events{/privacy}","received_events_url":"https://api.github.com/users/kendonB/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-08-09T22:08:00Z","updated_at":"2016-09-22T03:32:21Z","closed_at":"2016-09-21T13:07:49Z","pull_request":{"url":"https://api.github.com/repos/hadley/purrr/pulls/221","html_url":"https://github.com/hadley/purrr/pull/221","diff_url":"https://github.com/hadley/purrr/pull/221.diff","patch_url":"https://github.com/hadley/purrr/pull/221.patch"},"body":"This can help people dealing with the issue at https://github.com/hadley/tidyr/issues/224.\r\n\r\nAdds create_env and in_new_env.\r\n\r\nTypical usage would be something like:\r\n\r\n```\r\n# More explicit what;s going on\r\nlist(iris_new_env = iris) %>% \r\n  create_env() %>% \r\n  with({\r\n    lm(Sepal.Width ~ Sepal.Length, iris_new_env)\r\n  })\r\n\r\n# and simpler syntax:\r\nin_new_env(lm)(Sepal.Width ~ Sepal.Length, iris_new_env)\r\n```\r\n\r\nAnd here it is in action fixing the above issue:\r\n```\r\nlibrary(dplyr)\r\nlibrary(purrr)\r\nlibrary(ggplot2)\r\niris_big <- iris %>% as.tbl() %>%  \r\n  mutate(iris = rep(list(iris), NROW(.)))\r\n\r\niris_big3 <- iris_big %>% \r\n  mutate(plot = iris %>% map(function(x){\r\n    Seatbelts_big <- Seatbelts %>% data.frame() %>% as.tbl() %>%  \r\n      mutate(Seatbelts = rep(list(Seatbelts), NROW(.))) \r\n    # Now use the new function\r\n    list(x = x) %>% \r\n      create_env() %>% \r\n      with({\r\n        x %>% ggplot(aes(x = Sepal.Length, y = Sepal.Width)) + geom_point()\r\n      })\r\n  }))\r\n\r\n# Size in memory is reasonable (but when calling this using multidplyr it isn't)\r\nobject.size(iris_big3)\r\n# 2759016 bytes\r\nsave(iris_big3, file = \"tmp.RData\")\r\nfile.size(\"tmp.RData\")\r\n# Size on disk is now correct.\r\n# 77221 (3% of memory used)\r\n\r\n# And similarly with in_new_env:\r\niris_big3 <- iris_big %>% \r\n  mutate(plot = iris %>% map(function(x){\r\n    Seatbelts_big <- Seatbelts %>% data.frame() %>% as.tbl() %>%  \r\n      mutate(Seatbelts = rep(list(Seatbelts), NROW(.))) \r\n    # Now use the new function\r\n    in_new_env(ggplot)(x, aes(x = Sepal.Length, y = Sepal.Width)) + geom_point()\r\n  }))\r\n\r\n```"},"comment":{"url":"https://api.github.com/repos/hadley/purrr/issues/comments/248802303","html_url":"https://github.com/hadley/purrr/pull/221#issuecomment-248802303","issue_url":"https://api.github.com/repos/hadley/purrr/issues/221","id":248802303,"user":{"login":"kendonB","id":5327505,"avatar_url":"https://avatars.githubusercontent.com/u/5327505?v=3","gravatar_id":"","url":"https://api.github.com/users/kendonB","html_url":"https://github.com/kendonB","followers_url":"https://api.github.com/users/kendonB/followers","following_url":"https://api.github.com/users/kendonB/following{/other_user}","gists_url":"https://api.github.com/users/kendonB/gists{/gist_id}","starred_url":"https://api.github.com/users/kendonB/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kendonB/subscriptions","organizations_url":"https://api.github.com/users/kendonB/orgs","repos_url":"https://api.github.com/users/kendonB/repos","events_url":"https://api.github.com/users/kendonB/events{/privacy}","received_events_url":"https://api.github.com/users/kendonB/received_events","type":"User","site_admin":false},"created_at":"2016-09-22T03:32:21Z","updated_at":"2016-09-22T03:32:21Z","body":"Should I file an issue?"}}
{"actor":{"display_login":"kendonB"}}