{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/67782797","id":67782797,"diff_hunk":"@@ -262,6 +262,79 @@ head(df)\n {% endhighlight %}\n </div>\n \n+### Applying User-defined Function\n+In SparkR, we support several kinds for User-defined Functions:\n+\n+#### Run a given function on a large dataset using `dapply` or `dapplyCollect`\n+\n+##### dapply\n+Apply a function to each partition of `SparkDataFrame`. The function to be applied to each partition of the `SparkDataFrame`\n+and should have only one parameter, to which a `data.frame` corresponds to each partition will be passed. The output of function\n+should be a `data.frame`. Schema specifies the row format of the resulting `SparkDataFrame`. It must match the R function's output.\n+<div data-lang=\"r\"  markdown=\"1\">\n+{% highlight r %}\n+\n+# Convert waiting time from hours to seconds.\n+# Note that we can apply UDF to DataFrame.\n+schema <- structType(structField(\"eruptions\", \"double\"), structField(\"waiting\", \"double\"),\n+                     structField(\"waiting_secs\", \"double\"))\n+df1 <- dapply(df, function(x) {x <- cbind(x, x$waiting * 60)}, schema)\n+head(collect(df1))\n+##  eruptions waiting waiting_secs\n+##1     3.600      79         4740\n+##2     1.800      54         3240\n+##3     3.333      74         4440\n+##4     2.283      62         3720\n+##5     4.533      85         5100\n+##6     2.883      55         3300\n+{% endhighlight %}\n+</div>\n+\n+##### dapplyCollect\n+Like `dapply`, apply a function to each partition of `SparkDataFrame` and collect the result back.\n+<div data-lang=\"r\"  markdown=\"1\">\n+{% highlight r %}\n+\n+# Convert waiting time from hours to seconds.\n+# Note that we can apply UDF to DataFrame and return a R's data.frame\n+ldf <- dapplyCollect(\n+         df,\n+         function(x) {\n+           x <- cbind(x, \"waiting_secs\"=x$waiting * 60)\n+         })\n+head(ldf, 3)\n+##  eruptions waiting waiting_secs\n+##1     3.600      79         4740\n+##2     1.800      54         3240\n+##3     3.333      74         4440\n+\n+{% endhighlight %}\n+</div>\n+\n+#### Run many functions in parallel using `spark.lapply`\n+\n+##### lapply\n+Similar to `lapply` in native R, `spark.lapply` runs a function over a list of elements and distributes the computations with Spark.\n+Applies a function in a manner that is similar to `doParallel` or `lapply` to elements of a list.","path":"docs/sparkr.md","position":57,"original_position":57,"commit_id":"3f2aea9e6c909ec271e146073865b13551d90c27","original_commit_id":"3f2aea9e6c909ec271e146073865b13551d90c27","user":{"login":"vectorijk","id":3419881,"avatar_url":"https://avatars.githubusercontent.com/u/3419881?v=3","gravatar_id":"","url":"https://api.github.com/users/vectorijk","html_url":"https://github.com/vectorijk","followers_url":"https://api.github.com/users/vectorijk/followers","following_url":"https://api.github.com/users/vectorijk/following{/other_user}","gists_url":"https://api.github.com/users/vectorijk/gists{/gist_id}","starred_url":"https://api.github.com/users/vectorijk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vectorijk/subscriptions","organizations_url":"https://api.github.com/users/vectorijk/orgs","repos_url":"https://api.github.com/users/vectorijk/repos","events_url":"https://api.github.com/users/vectorijk/events{/privacy}","received_events_url":"https://api.github.com/users/vectorijk/received_events","type":"User","site_admin":false},"body":"Thanks so much for pointing out this! I will update those very soon.","created_at":"2016-06-20T23:04:49Z","updated_at":"2016-06-20T23:04:50Z","html_url":"https://github.com/apache/spark/pull/13660#discussion_r67782797","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/13660","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/67782797"},"html":{"href":"https://github.com/apache/spark/pull/13660#discussion_r67782797"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/13660"}}},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/13660","id":73713677,"html_url":"https://github.com/apache/spark/pull/13660","diff_url":"https://github.com/apache/spark/pull/13660.diff","patch_url":"https://github.com/apache/spark/pull/13660.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/13660","number":13660,"state":"open","locked":false,"title":"[SPARK-15672][R][DOC] R programming guide update","user":{"login":"vectorijk","id":3419881,"avatar_url":"https://avatars.githubusercontent.com/u/3419881?v=3","gravatar_id":"","url":"https://api.github.com/users/vectorijk","html_url":"https://github.com/vectorijk","followers_url":"https://api.github.com/users/vectorijk/followers","following_url":"https://api.github.com/users/vectorijk/following{/other_user}","gists_url":"https://api.github.com/users/vectorijk/gists{/gist_id}","starred_url":"https://api.github.com/users/vectorijk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vectorijk/subscriptions","organizations_url":"https://api.github.com/users/vectorijk/orgs","repos_url":"https://api.github.com/users/vectorijk/repos","events_url":"https://api.github.com/users/vectorijk/events{/privacy}","received_events_url":"https://api.github.com/users/vectorijk/received_events","type":"User","site_admin":false},"body":"## What changes were proposed in this pull request?\r\nGuide for\r\n- UDFs with dapply, dapplyCollect\r\n- spark.lapply for running parallel R functions\r\n\r\n## How was this patch tested?\r\nbuild locally\r\n<img width=\"654\" alt=\"screen shot 2016-06-14 at 03 12 56\" src=\"https://cloud.githubusercontent.com/assets/3419881/16039344/12a3b6a0-31de-11e6-8d77-fe23308075c0.png\">\r\n","created_at":"2016-06-14T10:15:06Z","updated_at":"2016-06-20T23:04:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"88e84dfef181e5848e4494bd3797fc8ebcd72a5e","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/13660/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/13660/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/spark/issues/13660/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/3f2aea9e6c909ec271e146073865b13551d90c27","head":{"label":"vectorijk:spark-15672-R-guide-update","ref":"spark-15672-R-guide-update","sha":"3f2aea9e6c909ec271e146073865b13551d90c27","user":{"login":"vectorijk","id":3419881,"avatar_url":"https://avatars.githubusercontent.com/u/3419881?v=3","gravatar_id":"","url":"https://api.github.com/users/vectorijk","html_url":"https://github.com/vectorijk","followers_url":"https://api.github.com/users/vectorijk/followers","following_url":"https://api.github.com/users/vectorijk/following{/other_user}","gists_url":"https://api.github.com/users/vectorijk/gists{/gist_id}","starred_url":"https://api.github.com/users/vectorijk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vectorijk/subscriptions","organizations_url":"https://api.github.com/users/vectorijk/orgs","repos_url":"https://api.github.com/users/vectorijk/repos","events_url":"https://api.github.com/users/vectorijk/events{/privacy}","received_events_url":"https://api.github.com/users/vectorijk/received_events","type":"User","site_admin":false},"repo":{"id":43246256,"name":"spark","full_name":"vectorijk/spark","owner":{"login":"vectorijk","id":3419881,"avatar_url":"https://avatars.githubusercontent.com/u/3419881?v=3","gravatar_id":"","url":"https://api.github.com/users/vectorijk","html_url":"https://github.com/vectorijk","followers_url":"https://api.github.com/users/vectorijk/followers","following_url":"https://api.github.com/users/vectorijk/following{/other_user}","gists_url":"https://api.github.com/users/vectorijk/gists{/gist_id}","starred_url":"https://api.github.com/users/vectorijk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vectorijk/subscriptions","organizations_url":"https://api.github.com/users/vectorijk/orgs","repos_url":"https://api.github.com/users/vectorijk/repos","events_url":"https://api.github.com/users/vectorijk/events{/privacy}","received_events_url":"https://api.github.com/users/vectorijk/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/vectorijk/spark","description":"Mirror of Apache Spark","fork":true,"url":"https://api.github.com/repos/vectorijk/spark","forks_url":"https://api.github.com/repos/vectorijk/spark/forks","keys_url":"https://api.github.com/repos/vectorijk/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/vectorijk/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/vectorijk/spark/teams","hooks_url":"https://api.github.com/repos/vectorijk/spark/hooks","issue_events_url":"https://api.github.com/repos/vectorijk/spark/issues/events{/number}","events_url":"https://api.github.com/repos/vectorijk/spark/events","assignees_url":"https://api.github.com/repos/vectorijk/spark/assignees{/user}","branches_url":"https://api.github.com/repos/vectorijk/spark/branches{/branch}","tags_url":"https://api.github.com/repos/vectorijk/spark/tags","blobs_url":"https://api.github.com/repos/vectorijk/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/vectorijk/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/vectorijk/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/vectorijk/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/vectorijk/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/vectorijk/spark/languages","stargazers_url":"https://api.github.com/repos/vectorijk/spark/stargazers","contributors_url":"https://api.github.com/repos/vectorijk/spark/contributors","subscribers_url":"https://api.github.com/repos/vectorijk/spark/subscribers","subscription_url":"https://api.github.com/repos/vectorijk/spark/subscription","commits_url":"https://api.github.com/repos/vectorijk/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/vectorijk/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/vectorijk/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/vectorijk/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/vectorijk/spark/contents/{+path}","compare_url":"https://api.github.com/repos/vectorijk/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/vectorijk/spark/merges","archive_url":"https://api.github.com/repos/vectorijk/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/vectorijk/spark/downloads","issues_url":"https://api.github.com/repos/vectorijk/spark/issues{/number}","pulls_url":"https://api.github.com/repos/vectorijk/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/vectorijk/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/vectorijk/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/vectorijk/spark/labels{/name}","releases_url":"https://api.github.com/repos/vectorijk/spark/releases{/id}","deployments_url":"https://api.github.com/repos/vectorijk/spark/deployments","created_at":"2015-09-27T12:46:22Z","updated_at":"2016-01-20T07:40:01Z","pushed_at":"2016-06-20T18:56:29Z","git_url":"git://github.com/vectorijk/spark.git","ssh_url":"git@github.com:vectorijk/spark.git","clone_url":"https://github.com/vectorijk/spark.git","svn_url":"https://github.com/vectorijk/spark","homepage":null,"size":166912,"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":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"ce3b98bae28af72299722f56e4e4ef831f471ec0","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}","deployments_url":"https://api.github.com/repos/apache/spark/deployments","created_at":"2014-02-25T08:00:08Z","updated_at":"2016-06-20T21:58:26Z","pushed_at":"2016-06-20T22:55:16Z","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":490527,"stargazers_count":8983,"watchers_count":8983,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":8347,"mirror_url":"git://git.apache.org/spark.git","open_issues_count":385,"forks":8347,"open_issues":385,"watchers":8983,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/13660"},"html":{"href":"https://github.com/apache/spark/pull/13660"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/13660"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/13660/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/13660/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/13660/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/3f2aea9e6c909ec271e146073865b13551d90c27"}}}}
{"actor":{"display_login":"vectorijk"}}