From f5038c062988b1d7fe6b6c6275b9f767dbc94689 Mon Sep 17 00:00:00 2001 From: lythesia Date: Sun, 8 Feb 2015 11:49:18 +0800 Subject: [PATCH] pull out anonymous functions in groupByKey --- pkg/R/RDD.R | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/pkg/R/RDD.R b/pkg/R/RDD.R index 6b6fc5a1757d0..f321f874c8abf 100644 --- a/pkg/R/RDD.R +++ b/pkg/R/RDD.R @@ -1383,20 +1383,21 @@ setMethod("groupByKey", vals <- new.env() keys <- new.env() pred <- function(item) exists(item$hash, keys) + appendList <- function(acc, x) { + addItemToAccumulator(acc, x) + acc + } + makeList <- function(x) { + acc <- initAccumulator() + addItemToAccumulator(acc, x) + acc + } # Each item in the partition is list of (K, V) lapply(part, function(item) { item$hash <- as.character(hashCode(item[[1]])) updateOrCreatePair(item, keys, vals, pred, - function(acc, x) { - addItemToAccumulator(acc, x) - acc - }, - function(x) { - acc <- initAccumulator() - addItemToAccumulator(acc, x) - acc - }) + appendList, makeList) }) # extract out data field vals <- eapply(vals,