{"action":"created","comment":{"url":"https://api.github.com/repos/krlmlr/deparse/pulls/comments/113559344","pull_request_review_id":34958719,"id":113559344,"diff_hunk":"@@ -0,0 +1,137 @@\n+#' @export\n+deparse.data.frame <-\n+  function(x, as_tibble = FALSE, as_tribble = FALSE, generate_mutate = TRUE, ...) {\n+\n+  if (as_tribble) {\n+    return(deparse_tribble(x, generate_mutate, ...))\n+  }\n+\n+  col_names <- vapply(names(x), function(nm) deparse(as.name(nm)), character(1))\n+  columns <- sprintf(\"%s = %s\", col_names, vapply(x, deparse, character(1)))\n+\n+  if (any(row.names(x) != as.character(seq_len(nrow(x))))) {\n+    if (as_tibble) {\n+      warning(\"row.names are not supported by `tibble`\")\n+    } else {\n+      columns <- c(columns, sprintf(\"row.names = %s\",\n+                                    deparse(attr(x, \"row.names\"))))\n+    }\n+  }\n+\n+  if (as_tibble) {\n+    sprintf(\"tibble(%s)\",\n+            paste(columns, collapse = \", \"))\n+  } else {\n+    sprintf(\"data.frame(%s, stringsAsFactors = FALSE, check.names = FALSE)\",\n+            paste(columns, collapse = \", \"))\n+  }\n+}\n+\n+#' @export\n+deparse.tbl_df <- function(x, as_tibble = TRUE, as_tribble = FALSE, ...) {\n+  deparse.data.frame(x = x, as_tibble = as_tibble, as_tribble = as_tribble, ...)\n+}\n+\n+deparse_tribble <- function(x, generate_mutate, ...) {\n+  col_names <- names(x)\n+\n+  row_item_calls <- list(quote(`:`), quote(c), quote(list))\n+\n+  # Finds an appropriate vector wrapped in function calls and replaces the\n+  # vector with the column name\n+  # Returns NULL if there is no matching vector\n+  find_and_replace_c <- function(cur_call, col_name, n_rows) {\n+    if ((!is.call(cur_call) && n_rows == 1) ||\n+        (is.call(cur_call) && some(row_item_calls, identical, cur_call[[1L]]) &&\n+        length(eval(cur_call)) == n_rows)) {\n+      return(list(col_data = cur_call, call = as.symbol(col_name)))\n+    }\n+    if (is.call(cur_call) && length(cur_call) > 1L) {\n+      res <- find_and_replace_c(cur_call[[2L]], col_name, n_rows)\n+      if (!is.null(res)) {\n+        cur_call[[2L]] <- res$call\n+        return(list(col_data = res$col_data, call = cur_call))\n+      } else {\n+        return(NULL)\n+      }\n+    }\n+    return(NULL)\n+  }\n+\n+  generate_column_calls <- function(column, col_name) {\n+    col_dp <- deparsec(column)\n+    col_call <- NULL\n+    if (is.call(col_dp)) {\n+      if (!some(row_item_calls, identical, col_dp[[1L]]) &&\n+          length(col_dp) > 1L && !identical(col_dp[[1L]], quote(list))) {\n+        res <- find_and_replace_c(col_dp[[2L]], col_name, nrow(x))\n+        if (!is.null(res)) {\n+          col_call <- col_dp\n+          col_call[[2L]] <- res$call\n+          column <- eval(res$col_data)\n+        }\n+      }\n+    }\n+    return(list(col_data = column, col_call = col_call))\n+  }\n+\n+  col_calls <- list()\n+\n+  output_data <- character(nrow(x) * ncol(x))\n+  dim(output_data) <- dim(x)\n+\n+  for (i in seq_along(x)) {\n+      res <- generate_column_calls(x[[i]], col_names[i])\n+      if (generate_mutate) {\n+        output_data[, i] <- map_chr(res$col_data, deparse, ...)\n+      } else {\n+        output_data[, i] <- map_chr(x[[i]], deparse, ...)\n+      }\n+      if (!is.null(res$col_call)) {\n+        col_calls <- c(\n+          col_calls,\n+          stats::setNames(list(deparse(res$col_call)), col_names[i])\n+        )\n+      }\n+  }\n+\n+  syntactic_name <- function(x) {\n+    base::deparse(as.symbol(x), backtick = TRUE)\n+  }\n+  output_col_names <- paste0(\n+    \"~\",\n+    map_chr(col_names, syntactic_name)\n+  )\n+\n+  output_collapsed <- map_chr(\n+    1:nrow(x),\n+    function(i) paste(output_data[i, ], collapse = \", \")\n+  )\n+\n+  output_final <- paste0(\n+    \"tribble(\\n  \",\n+    paste(\n+      c(paste(output_col_names, collapse = \", \"), output_collapsed),\n+      collapse = \",\\n  \"\n+      ),\n+    \"\\n  )\"\n+    )\n+\n+  if (length(col_calls) > 0L) {\n+    if (generate_mutate) {\n+      output_final <- paste0(\n+        output_final,\n+        \" %>% \\n\",\n+        \"  mutate(\\n\",\n+        paste(\n+          sprintf(\"    %s = %s\", names(col_calls), col_calls),\n+          collapse = \",\\n\"\n+          ),\n+        \"\\n  )\"\n+      )\n+    } else {\n+      warning(\"Without `generate_mutate`, deparsed code may not function correctly on types such as factors\")","path":"R/deparse-data-frame.R","position":172,"original_position":133,"commit_id":"b49f62c59bf7b3674269245ad1169e571bc35490","original_commit_id":"58d41ad276375372d2dcdee60fa37b7777a1ae34","user":{"login":"krlmlr","id":1741643,"avatar_url":"https://avatars3.githubusercontent.com/u/1741643?v=3","gravatar_id":"","url":"https://api.github.com/users/krlmlr","html_url":"https://github.com/krlmlr","followers_url":"https://api.github.com/users/krlmlr/followers","following_url":"https://api.github.com/users/krlmlr/following{/other_user}","gists_url":"https://api.github.com/users/krlmlr/gists{/gist_id}","starred_url":"https://api.github.com/users/krlmlr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/krlmlr/subscriptions","organizations_url":"https://api.github.com/users/krlmlr/orgs","repos_url":"https://api.github.com/users/krlmlr/repos","events_url":"https://api.github.com/users/krlmlr/events{/privacy}","received_events_url":"https://api.github.com/users/krlmlr/received_events","type":"User","site_admin":false},"body":"I still see `warning()` in the line above.","created_at":"2017-04-26T20:51:05Z","updated_at":"2017-04-26T21:03:49Z","html_url":"https://github.com/krlmlr/deparse/pull/4#discussion_r113559344","pull_request_url":"https://api.github.com/repos/krlmlr/deparse/pulls/4","_links":{"self":{"href":"https://api.github.com/repos/krlmlr/deparse/pulls/comments/113559344"},"html":{"href":"https://github.com/krlmlr/deparse/pull/4#discussion_r113559344"},"pull_request":{"href":"https://api.github.com/repos/krlmlr/deparse/pulls/4"}}},"pull_request":{"url":"https://api.github.com/repos/krlmlr/deparse/pulls/4","id":117560819,"html_url":"https://github.com/krlmlr/deparse/pull/4","diff_url":"https://github.com/krlmlr/deparse/pull/4.diff","patch_url":"https://github.com/krlmlr/deparse/pull/4.patch","issue_url":"https://api.github.com/repos/krlmlr/deparse/issues/4","number":4,"state":"open","locked":false,"title":"Suggested starting point for `deparse`","user":{"login":"NikNakk","id":2175487,"avatar_url":"https://avatars0.githubusercontent.com/u/2175487?v=3","gravatar_id":"","url":"https://api.github.com/users/NikNakk","html_url":"https://github.com/NikNakk","followers_url":"https://api.github.com/users/NikNakk/followers","following_url":"https://api.github.com/users/NikNakk/following{/other_user}","gists_url":"https://api.github.com/users/NikNakk/gists{/gist_id}","starred_url":"https://api.github.com/users/NikNakk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NikNakk/subscriptions","organizations_url":"https://api.github.com/users/NikNakk/orgs","repos_url":"https://api.github.com/users/NikNakk/repos","events_url":"https://api.github.com/users/NikNakk/events{/privacy}","received_events_url":"https://api.github.com/users/NikNakk/received_events","type":"User","site_admin":false},"body":"There's now the beginnings of a workable `deparse` package with support for factors, lists, data.frames, tibbles. It includes an `as_tribble` option for data.frames and tibbles.\r\n\r\nLet me know what you think.","created_at":"2017-04-25T19:20:44Z","updated_at":"2017-04-26T21:03:49Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a1a735d16c675e7ab6303f840fabc5a07a97ff97","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/krlmlr/deparse/pulls/4/commits","review_comments_url":"https://api.github.com/repos/krlmlr/deparse/pulls/4/comments","review_comment_url":"https://api.github.com/repos/krlmlr/deparse/pulls/comments{/number}","comments_url":"https://api.github.com/repos/krlmlr/deparse/issues/4/comments","statuses_url":"https://api.github.com/repos/krlmlr/deparse/statuses/b49f62c59bf7b3674269245ad1169e571bc35490","head":{"label":"NikNakk:master","ref":"master","sha":"b49f62c59bf7b3674269245ad1169e571bc35490","user":{"login":"NikNakk","id":2175487,"avatar_url":"https://avatars0.githubusercontent.com/u/2175487?v=3","gravatar_id":"","url":"https://api.github.com/users/NikNakk","html_url":"https://github.com/NikNakk","followers_url":"https://api.github.com/users/NikNakk/followers","following_url":"https://api.github.com/users/NikNakk/following{/other_user}","gists_url":"https://api.github.com/users/NikNakk/gists{/gist_id}","starred_url":"https://api.github.com/users/NikNakk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NikNakk/subscriptions","organizations_url":"https://api.github.com/users/NikNakk/orgs","repos_url":"https://api.github.com/users/NikNakk/repos","events_url":"https://api.github.com/users/NikNakk/events{/privacy}","received_events_url":"https://api.github.com/users/NikNakk/received_events","type":"User","site_admin":false},"repo":{"id":88679156,"name":"deparse","full_name":"NikNakk/deparse","owner":{"login":"NikNakk","id":2175487,"avatar_url":"https://avatars0.githubusercontent.com/u/2175487?v=3","gravatar_id":"","url":"https://api.github.com/users/NikNakk","html_url":"https://github.com/NikNakk","followers_url":"https://api.github.com/users/NikNakk/followers","following_url":"https://api.github.com/users/NikNakk/following{/other_user}","gists_url":"https://api.github.com/users/NikNakk/gists{/gist_id}","starred_url":"https://api.github.com/users/NikNakk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NikNakk/subscriptions","organizations_url":"https://api.github.com/users/NikNakk/orgs","repos_url":"https://api.github.com/users/NikNakk/repos","events_url":"https://api.github.com/users/NikNakk/events{/privacy}","received_events_url":"https://api.github.com/users/NikNakk/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/NikNakk/deparse","description":"A nicer deparse","fork":true,"url":"https://api.github.com/repos/NikNakk/deparse","forks_url":"https://api.github.com/repos/NikNakk/deparse/forks","keys_url":"https://api.github.com/repos/NikNakk/deparse/keys{/key_id}","collaborators_url":"https://api.github.com/repos/NikNakk/deparse/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/NikNakk/deparse/teams","hooks_url":"https://api.github.com/repos/NikNakk/deparse/hooks","issue_events_url":"https://api.github.com/repos/NikNakk/deparse/issues/events{/number}","events_url":"https://api.github.com/repos/NikNakk/deparse/events","assignees_url":"https://api.github.com/repos/NikNakk/deparse/assignees{/user}","branches_url":"https://api.github.com/repos/NikNakk/deparse/branches{/branch}","tags_url":"https://api.github.com/repos/NikNakk/deparse/tags","blobs_url":"https://api.github.com/repos/NikNakk/deparse/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/NikNakk/deparse/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/NikNakk/deparse/git/refs{/sha}","trees_url":"https://api.github.com/repos/NikNakk/deparse/git/trees{/sha}","statuses_url":"https://api.github.com/repos/NikNakk/deparse/statuses/{sha}","languages_url":"https://api.github.com/repos/NikNakk/deparse/languages","stargazers_url":"https://api.github.com/repos/NikNakk/deparse/stargazers","contributors_url":"https://api.github.com/repos/NikNakk/deparse/contributors","subscribers_url":"https://api.github.com/repos/NikNakk/deparse/subscribers","subscription_url":"https://api.github.com/repos/NikNakk/deparse/subscription","commits_url":"https://api.github.com/repos/NikNakk/deparse/commits{/sha}","git_commits_url":"https://api.github.com/repos/NikNakk/deparse/git/commits{/sha}","comments_url":"https://api.github.com/repos/NikNakk/deparse/comments{/number}","issue_comment_url":"https://api.github.com/repos/NikNakk/deparse/issues/comments{/number}","contents_url":"https://api.github.com/repos/NikNakk/deparse/contents/{+path}","compare_url":"https://api.github.com/repos/NikNakk/deparse/compare/{base}...{head}","merges_url":"https://api.github.com/repos/NikNakk/deparse/merges","archive_url":"https://api.github.com/repos/NikNakk/deparse/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/NikNakk/deparse/downloads","issues_url":"https://api.github.com/repos/NikNakk/deparse/issues{/number}","pulls_url":"https://api.github.com/repos/NikNakk/deparse/pulls{/number}","milestones_url":"https://api.github.com/repos/NikNakk/deparse/milestones{/number}","notifications_url":"https://api.github.com/repos/NikNakk/deparse/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/NikNakk/deparse/labels{/name}","releases_url":"https://api.github.com/repos/NikNakk/deparse/releases{/id}","deployments_url":"https://api.github.com/repos/NikNakk/deparse/deployments","created_at":"2017-04-18T23:24:39Z","updated_at":"2017-04-18T23:24:41Z","pushed_at":"2017-04-26T08:07:58Z","git_url":"git://github.com/NikNakk/deparse.git","ssh_url":"git@github.com:NikNakk/deparse.git","clone_url":"https://github.com/NikNakk/deparse.git","svn_url":"https://github.com/NikNakk/deparse","homepage":"","size":39,"stargazers_count":0,"watchers_count":0,"language":"R","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"krlmlr:master","ref":"master","sha":"1a8f77e10e10db88af78b026a240009baeb3ffc9","user":{"login":"krlmlr","id":1741643,"avatar_url":"https://avatars3.githubusercontent.com/u/1741643?v=3","gravatar_id":"","url":"https://api.github.com/users/krlmlr","html_url":"https://github.com/krlmlr","followers_url":"https://api.github.com/users/krlmlr/followers","following_url":"https://api.github.com/users/krlmlr/following{/other_user}","gists_url":"https://api.github.com/users/krlmlr/gists{/gist_id}","starred_url":"https://api.github.com/users/krlmlr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/krlmlr/subscriptions","organizations_url":"https://api.github.com/users/krlmlr/orgs","repos_url":"https://api.github.com/users/krlmlr/repos","events_url":"https://api.github.com/users/krlmlr/events{/privacy}","received_events_url":"https://api.github.com/users/krlmlr/received_events","type":"User","site_admin":false},"repo":{"id":65830221,"name":"deparse","full_name":"krlmlr/deparse","owner":{"login":"krlmlr","id":1741643,"avatar_url":"https://avatars3.githubusercontent.com/u/1741643?v=3","gravatar_id":"","url":"https://api.github.com/users/krlmlr","html_url":"https://github.com/krlmlr","followers_url":"https://api.github.com/users/krlmlr/followers","following_url":"https://api.github.com/users/krlmlr/following{/other_user}","gists_url":"https://api.github.com/users/krlmlr/gists{/gist_id}","starred_url":"https://api.github.com/users/krlmlr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/krlmlr/subscriptions","organizations_url":"https://api.github.com/users/krlmlr/orgs","repos_url":"https://api.github.com/users/krlmlr/repos","events_url":"https://api.github.com/users/krlmlr/events{/privacy}","received_events_url":"https://api.github.com/users/krlmlr/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/krlmlr/deparse","description":"A nicer deparse","fork":false,"url":"https://api.github.com/repos/krlmlr/deparse","forks_url":"https://api.github.com/repos/krlmlr/deparse/forks","keys_url":"https://api.github.com/repos/krlmlr/deparse/keys{/key_id}","collaborators_url":"https://api.github.com/repos/krlmlr/deparse/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/krlmlr/deparse/teams","hooks_url":"https://api.github.com/repos/krlmlr/deparse/hooks","issue_events_url":"https://api.github.com/repos/krlmlr/deparse/issues/events{/number}","events_url":"https://api.github.com/repos/krlmlr/deparse/events","assignees_url":"https://api.github.com/repos/krlmlr/deparse/assignees{/user}","branches_url":"https://api.github.com/repos/krlmlr/deparse/branches{/branch}","tags_url":"https://api.github.com/repos/krlmlr/deparse/tags","blobs_url":"https://api.github.com/repos/krlmlr/deparse/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/krlmlr/deparse/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/krlmlr/deparse/git/refs{/sha}","trees_url":"https://api.github.com/repos/krlmlr/deparse/git/trees{/sha}","statuses_url":"https://api.github.com/repos/krlmlr/deparse/statuses/{sha}","languages_url":"https://api.github.com/repos/krlmlr/deparse/languages","stargazers_url":"https://api.github.com/repos/krlmlr/deparse/stargazers","contributors_url":"https://api.github.com/repos/krlmlr/deparse/contributors","subscribers_url":"https://api.github.com/repos/krlmlr/deparse/subscribers","subscription_url":"https://api.github.com/repos/krlmlr/deparse/subscription","commits_url":"https://api.github.com/repos/krlmlr/deparse/commits{/sha}","git_commits_url":"https://api.github.com/repos/krlmlr/deparse/git/commits{/sha}","comments_url":"https://api.github.com/repos/krlmlr/deparse/comments{/number}","issue_comment_url":"https://api.github.com/repos/krlmlr/deparse/issues/comments{/number}","contents_url":"https://api.github.com/repos/krlmlr/deparse/contents/{+path}","compare_url":"https://api.github.com/repos/krlmlr/deparse/compare/{base}...{head}","merges_url":"https://api.github.com/repos/krlmlr/deparse/merges","archive_url":"https://api.github.com/repos/krlmlr/deparse/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/krlmlr/deparse/downloads","issues_url":"https://api.github.com/repos/krlmlr/deparse/issues{/number}","pulls_url":"https://api.github.com/repos/krlmlr/deparse/pulls{/number}","milestones_url":"https://api.github.com/repos/krlmlr/deparse/milestones{/number}","notifications_url":"https://api.github.com/repos/krlmlr/deparse/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/krlmlr/deparse/labels{/name}","releases_url":"https://api.github.com/repos/krlmlr/deparse/releases{/id}","deployments_url":"https://api.github.com/repos/krlmlr/deparse/deployments","created_at":"2016-08-16T15:10:18Z","updated_at":"2017-04-25T20:52:15Z","pushed_at":"2017-04-26T08:07:59Z","git_url":"git://github.com/krlmlr/deparse.git","ssh_url":"git@github.com:krlmlr/deparse.git","clone_url":"https://github.com/krlmlr/deparse.git","svn_url":"https://github.com/krlmlr/deparse","homepage":"","size":25,"stargazers_count":2,"watchers_count":2,"language":"R","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":4,"forks":1,"open_issues":4,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/krlmlr/deparse/pulls/4"},"html":{"href":"https://github.com/krlmlr/deparse/pull/4"},"issue":{"href":"https://api.github.com/repos/krlmlr/deparse/issues/4"},"comments":{"href":"https://api.github.com/repos/krlmlr/deparse/issues/4/comments"},"review_comments":{"href":"https://api.github.com/repos/krlmlr/deparse/pulls/4/comments"},"review_comment":{"href":"https://api.github.com/repos/krlmlr/deparse/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/krlmlr/deparse/pulls/4/commits"},"statuses":{"href":"https://api.github.com/repos/krlmlr/deparse/statuses/b49f62c59bf7b3674269245ad1169e571bc35490"}}}}
{"actor":{"display_login":"krlmlr"}}