Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions R/pkg/NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ exportMethods(
"saveAsObjectFile",
"sortBy",
"sortByKey",
"sumRDD",
"take",
"takeOrdered",
"takeSample",
Expand Down
17 changes: 17 additions & 0 deletions R/pkg/R/RDD.R
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,23 @@ setMethod("minimum",
reduce(x, min)
})

#' Add up the elements in an RDD.
#'
#' @param x The RDD to add up the elements in
#' @examples
#'\dontrun{
#' sc <- sparkR.init()
#' rdd <- parallelize(sc, 1:10)
#' sumRDD(rdd) # 55
#'}
#' @rdname sumRDD
#' @aliases sumRDD,RDD
setMethod("sumRDD",
signature(x = "RDD"),
function(x) {
reduce(x, "+")
})

#' Applies a function to all elements in an RDD, and force evaluation.
#'
#' @param x The RDD to apply the function
Expand Down
4 changes: 4 additions & 0 deletions R/pkg/R/generics.R
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ setGeneric("maximum", function(x) { standardGeneric("maximum") })
#' @export
setGeneric("minimum", function(x) { standardGeneric("minimum") })

#' @rdname sumRDD
#' @export
setGeneric("sumRDD", function(x) { standardGeneric("sumRDD") })

#' @rdname name
#' @export
setGeneric("name", function(x) { standardGeneric("name") })
Expand Down
5 changes: 5 additions & 0 deletions R/pkg/inst/tests/test_rdd.R
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,11 @@ test_that("minimum() on RDDs", {
expect_equal(min, 1)
})

test_that("sumRDD() on RDDs", {
sum <- sumRDD(rdd)
expect_equal(sum, 55)
})

test_that("keyBy on RDDs", {
func <- function(x) { x*x }
keys <- keyBy(rdd, func)
Expand Down