spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shivaram <...@git.apache.org>
Subject [GitHub] spark pull request: [SPARK-6806] [SparkR] [Docs] Fill in SparkR ex...
Date Fri, 10 Apr 2015 23:55:53 GMT
Github user shivaram commented on a diff in the pull request:

    https://github.com/apache/spark/pull/5442#discussion_r28188837
  
    --- Diff: docs/quick-start.md ---
    @@ -171,6 +205,44 @@ Here, we combined the [`flatMap`](programming-guide.html#transformations),
[`map
     {% endhighlight %}
     
     </div>
    +<div data-lang="r" markdown="1">
    +
    +{% highlight r %}
    +> reduce(map(textFile, function(line) { length(strsplit(line, " ")[[1]]) }), function(a,
b) {max(a, b)})
    +[1] 14
    +{% endhighlight %}
    +
    +This first maps a line to an integer value, creating a new RDD. `reduce` is called on
that RDD to find the largest line count. The arguments to `map` and `reduce` are R [anonymous
functions](http://adv-r.had.co.nz/Functional-programming.html#anonymous-functions),
    +but we can also pass any top-level R function we want.
    +For example, we'll define a `mymax` function to make this code easier to understand:
    +
    +{% highlight r %}
    +> mymax <- function(a, b) { max(a, b) }
    +> reduce(map(textFile, function(line) { length(strsplit(line, " ")[[1]]) }), mymax)
    +[1] 14
    +{% endhighlight %}
    +
    +One common data flow pattern is MapReduce, as popularized by Hadoop. Spark can implement
MapReduce flows easily:
    +
    +{% highlight r %}
    +> wordCounts <- reduceByKey(map(flatMap(textFile, function(line) strsplit(line,
" ")[[1]]), function(word) list(word, 1)), "+", 2)
    --- End diff --
    
    Can you split this into multiple lines, so it becomes more readable ? i.e. something like
    ```
    wordCounts <- reduceByKey(
      map(
        flatMap(textFile, function(line) strsplit(line, " ")[[1]]), 
        function(word) list(word, 1)), 
     "+",  2)
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Mime
View raw message