aboutsummaryrefslogtreecommitdiff
path: root/R/pkg/R/context.R
diff options
context:
space:
mode:
authorFelix Cheung <felixcheung_m@hotmail.com>2016-06-20 12:08:42 -0700
committerShivaram Venkataraman <shivaram@cs.berkeley.edu>2016-06-20 12:08:42 -0700
commit46d98e0a1f40a4c6ae92253c5c498a3a924497fc (patch)
tree0d8adc5a7093be7a87926c99572d6aeddcbf4ec4 /R/pkg/R/context.R
parentc44bf137c7ca649e0c504229eb3e6ff7955e9a53 (diff)
downloadspark-46d98e0a1f40a4c6ae92253c5c498a3a924497fc.tar.gz
spark-46d98e0a1f40a4c6ae92253c5c498a3a924497fc.tar.bz2
spark-46d98e0a1f40a4c6ae92253c5c498a3a924497fc.zip
[SPARK-16028][SPARKR] spark.lapply can work with active context
## What changes were proposed in this pull request? spark.lapply and setLogLevel ## How was this patch tested? unit test shivaram thunterdb Author: Felix Cheung <felixcheung_m@hotmail.com> Closes #13752 from felixcheung/rlapply.
Diffstat (limited to 'R/pkg/R/context.R')
-rw-r--r--R/pkg/R/context.R20
1 files changed, 13 insertions, 7 deletions
diff --git a/R/pkg/R/context.R b/R/pkg/R/context.R
index 5c886030ff..968a9d2251 100644
--- a/R/pkg/R/context.R
+++ b/R/pkg/R/context.R
@@ -252,17 +252,20 @@ setCheckpointDir <- function(sc, dirName) {
#' }
#'
#' @rdname spark.lapply
-#' @param sc Spark Context to use
#' @param list the list of elements
#' @param func a function that takes one argument.
#' @return a list of results (the exact type being determined by the function)
#' @export
#' @examples
#'\dontrun{
-#' sc <- sparkR.init()
-#' doubled <- spark.lapply(sc, 1:10, function(x){2 * x})
+#' sparkR.session()
+#' doubled <- spark.lapply(1:10, function(x){2 * x})
#'}
-spark.lapply <- function(sc, list, func) {
+spark.lapply <- function(list, func) {
+ if (!exists(".sparkRjsc", envir = .sparkREnv)) {
+ stop("SparkR has not been initialized. Please call sparkR.session()")
+ }
+ sc <- get(".sparkRjsc", envir = .sparkREnv)
rdd <- parallelize(sc, list, length(list))
results <- map(rdd, func)
local <- collect(results)
@@ -274,14 +277,17 @@ spark.lapply <- function(sc, list, func) {
#' Set new log level: "ALL", "DEBUG", "ERROR", "FATAL", "INFO", "OFF", "TRACE", "WARN"
#'
#' @rdname setLogLevel
-#' @param sc Spark Context to use
#' @param level New log level
#' @export
#' @examples
#'\dontrun{
-#' setLogLevel(sc, "ERROR")
+#' setLogLevel("ERROR")
#'}
-setLogLevel <- function(sc, level) {
+setLogLevel <- function(level) {
+ if (!exists(".sparkRjsc", envir = .sparkREnv)) {
+ stop("SparkR has not been initialized. Please call sparkR.session()")
+ }
+ sc <- get(".sparkRjsc", envir = .sparkREnv)
callJMethod(sc, "setLogLevel", level)
}