{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/41321101","id":41321101,"diff_hunk":"@@ -1881,3 +1881,31 @@ setMethod(\"as.data.frame\",\n             collect(x)\n           }\n )\n+\n+#' Returns the column types of a DataFrame.\n+#' \n+#' @name coltypes\n+#' @title Get column types of a DataFrame\n+#' @param x (DataFrame)\n+#' @return value (character) A character vector with the column types of the given DataFrame\n+#' @rdname coltypes\n+setMethod(\"coltypes\",\n+          signature(x = \"DataFrame\"),\n+          function(x) {\n+            # TODO: This may be moved as a global parameter\n+            # These are the supported data types and how they map to\n+            # R's data types\n+            DATA_TYPES <- c(\"string\"=\"character\",\n+                            \"double\"=\"numeric\",\n+                            \"int\"=\"integer\",\n+                            \"long\"=\"integer\",\n+                            \"boolean\"=\"long\"\n+            )\n+\n+            # Get the data types of the DataFrame by invoking dtypes() function.\n+            # Some post-processing is needed.\n+            types <- as.character(t(as.data.frame(dtypes(x))[2, ]))\n+\n+            # Map Spark data types into R's data types\n+            as.character(DATA_TYPES[types])","path":"R/pkg/R/DataFrame.R","position":30,"original_position":30,"commit_id":"b44152ea6294cb3caf0cf2f92660b690693beaf7","original_commit_id":"b44152ea6294cb3caf0cf2f92660b690693beaf7","user":{"login":"olarayej","id":13985649,"avatar_url":"https://avatars.githubusercontent.com/u/13985649?v=3","gravatar_id":"","url":"https://api.github.com/users/olarayej","html_url":"https://github.com/olarayej","followers_url":"https://api.github.com/users/olarayej/followers","following_url":"https://api.github.com/users/olarayej/following{/other_user}","gists_url":"https://api.github.com/users/olarayej/gists{/gist_id}","starred_url":"https://api.github.com/users/olarayej/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/olarayej/subscriptions","organizations_url":"https://api.github.com/users/olarayej/orgs","repos_url":"https://api.github.com/users/olarayej/repos","events_url":"https://api.github.com/users/olarayej/events{/privacy}","received_events_url":"https://api.github.com/users/olarayej/received_events","type":"User","site_admin":false},"body":"@felixcheung Yeah, that's a good point. I'm thinking coltypes() should always have an equivalent R data type for each column. We don't want method coltypes() to return NA's or throw an unsupported-type error cuz that would mean that the input DataFrame is inconsistent.\r\n\r\nTherefore, it'd be just a matter of putting in DATA_TYPES, the list all possible values returned by dtypes() (If I'm missing any). I couldn't find that in the docs. Could you point me to the list?\r\n\r\nFinally, I think the check for unsupported data types should be done instead in the coltypes()<- method and in the DataFrame initialization. coltypes() assumes the input DataFrame was assigned valid data types, which makes sense to me.","created_at":"2015-10-06T20:57:27Z","updated_at":"2015-10-06T20:57:27Z","html_url":"https://github.com/apache/spark/pull/8984#discussion_r41321101","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/8984","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/41321101"},"html":{"href":"https://github.com/apache/spark/pull/8984#discussion_r41321101"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/8984"}}},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/8984","id":46824898,"html_url":"https://github.com/apache/spark/pull/8984","diff_url":"https://github.com/apache/spark/pull/8984.diff","patch_url":"https://github.com/apache/spark/pull/8984.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/8984","number":8984,"state":"open","locked":false,"title":"[SPARK-10863][SPARKR] Method coltypes() to get R's data types of a DataFrame","user":{"login":"olarayej","id":13985649,"avatar_url":"https://avatars.githubusercontent.com/u/13985649?v=3","gravatar_id":"","url":"https://api.github.com/users/olarayej","html_url":"https://github.com/olarayej","followers_url":"https://api.github.com/users/olarayej/followers","following_url":"https://api.github.com/users/olarayej/following{/other_user}","gists_url":"https://api.github.com/users/olarayej/gists{/gist_id}","starred_url":"https://api.github.com/users/olarayej/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/olarayej/subscriptions","organizations_url":"https://api.github.com/users/olarayej/orgs","repos_url":"https://api.github.com/users/olarayej/repos","events_url":"https://api.github.com/users/olarayej/events{/privacy}","received_events_url":"https://api.github.com/users/olarayej/received_events","type":"User","site_admin":false},"body":"Method coltypes() to get R's data types of a DataFrame","created_at":"2015-10-05T19:49:16Z","updated_at":"2015-10-06T20:57:27Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ca977e3225ab510f6b11e0b95f9ed70d9559633f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/8984/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/8984/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/spark/issues/8984/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/b44152ea6294cb3caf0cf2f92660b690693beaf7","head":{"label":"olarayej:SPARK-10863-NEW9","ref":"SPARK-10863-NEW9","sha":"b44152ea6294cb3caf0cf2f92660b690693beaf7","user":{"login":"olarayej","id":13985649,"avatar_url":"https://avatars.githubusercontent.com/u/13985649?v=3","gravatar_id":"","url":"https://api.github.com/users/olarayej","html_url":"https://github.com/olarayej","followers_url":"https://api.github.com/users/olarayej/followers","following_url":"https://api.github.com/users/olarayej/following{/other_user}","gists_url":"https://api.github.com/users/olarayej/gists{/gist_id}","starred_url":"https://api.github.com/users/olarayej/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/olarayej/subscriptions","organizations_url":"https://api.github.com/users/olarayej/orgs","repos_url":"https://api.github.com/users/olarayej/repos","events_url":"https://api.github.com/users/olarayej/events{/privacy}","received_events_url":"https://api.github.com/users/olarayej/received_events","type":"User","site_admin":false},"repo":{"id":43019226,"name":"spark","full_name":"olarayej/spark","owner":{"login":"olarayej","id":13985649,"avatar_url":"https://avatars.githubusercontent.com/u/13985649?v=3","gravatar_id":"","url":"https://api.github.com/users/olarayej","html_url":"https://github.com/olarayej","followers_url":"https://api.github.com/users/olarayej/followers","following_url":"https://api.github.com/users/olarayej/following{/other_user}","gists_url":"https://api.github.com/users/olarayej/gists{/gist_id}","starred_url":"https://api.github.com/users/olarayej/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/olarayej/subscriptions","organizations_url":"https://api.github.com/users/olarayej/orgs","repos_url":"https://api.github.com/users/olarayej/repos","events_url":"https://api.github.com/users/olarayej/events{/privacy}","received_events_url":"https://api.github.com/users/olarayej/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/olarayej/spark","description":"Mirror of Apache Spark","fork":true,"url":"https://api.github.com/repos/olarayej/spark","forks_url":"https://api.github.com/repos/olarayej/spark/forks","keys_url":"https://api.github.com/repos/olarayej/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/olarayej/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/olarayej/spark/teams","hooks_url":"https://api.github.com/repos/olarayej/spark/hooks","issue_events_url":"https://api.github.com/repos/olarayej/spark/issues/events{/number}","events_url":"https://api.github.com/repos/olarayej/spark/events","assignees_url":"https://api.github.com/repos/olarayej/spark/assignees{/user}","branches_url":"https://api.github.com/repos/olarayej/spark/branches{/branch}","tags_url":"https://api.github.com/repos/olarayej/spark/tags","blobs_url":"https://api.github.com/repos/olarayej/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/olarayej/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/olarayej/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/olarayej/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/olarayej/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/olarayej/spark/languages","stargazers_url":"https://api.github.com/repos/olarayej/spark/stargazers","contributors_url":"https://api.github.com/repos/olarayej/spark/contributors","subscribers_url":"https://api.github.com/repos/olarayej/spark/subscribers","subscription_url":"https://api.github.com/repos/olarayej/spark/subscription","commits_url":"https://api.github.com/repos/olarayej/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/olarayej/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/olarayej/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/olarayej/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/olarayej/spark/contents/{+path}","compare_url":"https://api.github.com/repos/olarayej/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/olarayej/spark/merges","archive_url":"https://api.github.com/repos/olarayej/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/olarayej/spark/downloads","issues_url":"https://api.github.com/repos/olarayej/spark/issues{/number}","pulls_url":"https://api.github.com/repos/olarayej/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/olarayej/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/olarayej/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/olarayej/spark/labels{/name}","releases_url":"https://api.github.com/repos/olarayej/spark/releases{/id}","created_at":"2015-09-23T18:27:43Z","updated_at":"2015-09-23T18:28:14Z","pushed_at":"2015-10-05T19:40:59Z","git_url":"git://github.com/olarayej/spark.git","ssh_url":"git@github.com:olarayej/spark.git","clone_url":"https://github.com/olarayej/spark.git","svn_url":"https://github.com/olarayej/spark","homepage":null,"size":126473,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"883bd8fccf83aae7a2a847c9a6ca129fac86e6a3","user":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":17165658,"name":"spark","full_name":"apache/spark","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/spark","description":"Mirror of Apache Spark","fork":false,"url":"https://api.github.com/repos/apache/spark","forks_url":"https://api.github.com/repos/apache/spark/forks","keys_url":"https://api.github.com/repos/apache/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/spark/teams","hooks_url":"https://api.github.com/repos/apache/spark/hooks","issue_events_url":"https://api.github.com/repos/apache/spark/issues/events{/number}","events_url":"https://api.github.com/repos/apache/spark/events","assignees_url":"https://api.github.com/repos/apache/spark/assignees{/user}","branches_url":"https://api.github.com/repos/apache/spark/branches{/branch}","tags_url":"https://api.github.com/repos/apache/spark/tags","blobs_url":"https://api.github.com/repos/apache/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/spark/languages","stargazers_url":"https://api.github.com/repos/apache/spark/stargazers","contributors_url":"https://api.github.com/repos/apache/spark/contributors","subscribers_url":"https://api.github.com/repos/apache/spark/subscribers","subscription_url":"https://api.github.com/repos/apache/spark/subscription","commits_url":"https://api.github.com/repos/apache/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/spark/contents/{+path}","compare_url":"https://api.github.com/repos/apache/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/spark/merges","archive_url":"https://api.github.com/repos/apache/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/spark/downloads","issues_url":"https://api.github.com/repos/apache/spark/issues{/number}","pulls_url":"https://api.github.com/repos/apache/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/spark/labels{/name}","releases_url":"https://api.github.com/repos/apache/spark/releases{/id}","created_at":"2014-02-25T08:00:08Z","updated_at":"2015-10-06T20:04:12Z","pushed_at":"2015-10-06T20:50:57Z","git_url":"git://github.com/apache/spark.git","ssh_url":"git@github.com:apache/spark.git","clone_url":"https://github.com/apache/spark.git","svn_url":"https://github.com/apache/spark","homepage":null,"size":1628016,"stargazers_count":5676,"watchers_count":5676,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":5247,"mirror_url":"git://git.apache.org/spark.git","open_issues_count":356,"forks":5247,"open_issues":356,"watchers":5676,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/8984"},"html":{"href":"https://github.com/apache/spark/pull/8984"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/8984"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/8984/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/8984/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/8984/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/b44152ea6294cb3caf0cf2f92660b690693beaf7"}}}}