Skip to content

Commit cd1394a

Browse files
committed
change install.spark
1 parent f51f504 commit cd1394a

24 files changed

+18
-68
lines changed

R/pkg/R/install.R

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
#' Download and Install Apache Spark to a Local Directory
2222
#'
2323
#' \code{install.spark} downloads and installs Spark to a local directory if
24-
#' it is not found. The Spark version we use is the same as the SparkR version.
25-
#' Users can specify a desired Hadoop version, the remote mirror site, and
26-
#' the directory where the package is installed locally.
24+
#' it is not found. If SPARK_HOME is set in the environment, and that directory is found, that is
25+
#' returned. The Spark version we use is the same as the SparkR version. Users can specify a desired
26+
#' Hadoop version, the remote mirror site, and the directory where the package is installed locally.
2727
#'
2828
#' The full url of remote file is inferred from \code{mirrorUrl} and \code{hadoopVersion}.
2929
#' \code{mirrorUrl} specifies the remote path to a Spark folder. It is followed by a subfolder
@@ -68,6 +68,16 @@
6868
#' \href{http://spark.apache.org/downloads.html}{Apache Spark}
6969
install.spark <- function(hadoopVersion = "2.7", mirrorUrl = NULL,
7070
localDir = NULL, overwrite = FALSE) {
71+
sparkHome <- Sys.getenv("SPARK_HOME")
72+
if (isSparkRShell()) {
73+
stopifnot(nchar(sparkHome) > 0)
74+
message("Spark is already running in sparkR shell.")
75+
return(invisible(sparkHome))
76+
} else if (!is.na(file.info(sparkHome)$isdir)) {
77+
message("Spark package found in SPARK_HOME: ", sparkHome)
78+
return(invisible(sparkHome))
79+
}
80+
7181
version <- paste0("spark-", packageVersion("SparkR"))
7282
hadoopVersion <- tolower(hadoopVersion)
7383
hadoopVersionName <- hadoopVersionName(hadoopVersion)

R/pkg/R/sparkR.R

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -585,10 +585,7 @@ processSparkPackages <- function(packages) {
585585
# @param deployMode whether to deploy your driver on the worker nodes (cluster)
586586
# or locally as an external client (client).
587587
# @return NULL if no need to update sparkHome, and new sparkHome otherwise.
588-
sparkCheckInstall <- function(
589-
sparkHome = Sys.getenv("SPARK_HOME"),
590-
master = "local",
591-
deployMode = "") {
588+
sparkCheckInstall <- function(sparkHome, master, deployMode) {
592589
if (!isSparkRShell()) {
593590
if (!is.na(file.info(sparkHome)$isdir)) {
594591
message("Spark package found in SPARK_HOME: ", sparkHome)

R/pkg/inst/tests/testthat/test_Serde.R

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717

1818
context("SerDe functionality")
1919

20-
# Ensure Spark is installed
21-
sparkCheckInstall()
22-
2320
sparkSession <- sparkR.session(enableHiveSupport = FALSE)
2421

2522
test_that("SerDe of primitive types", {

R/pkg/inst/tests/testthat/test_binaryFile.R

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717

1818
context("functions on binary files")
1919

20-
# Ensure Spark is installed
21-
sparkCheckInstall()
22-
2320
# JavaSparkContext handle
2421
sparkSession <- sparkR.session(enableHiveSupport = FALSE)
2522
sc <- callJStatic("org.apache.spark.sql.api.r.SQLUtils", "getJavaSparkContext", sparkSession)

R/pkg/inst/tests/testthat/test_binary_function.R

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717

1818
context("binary functions")
1919

20-
# Ensure Spark is installed
21-
sparkCheckInstall()
22-
2320
# JavaSparkContext handle
2421
sparkSession <- sparkR.session(enableHiveSupport = FALSE)
2522
sc <- callJStatic("org.apache.spark.sql.api.r.SQLUtils", "getJavaSparkContext", sparkSession)

R/pkg/inst/tests/testthat/test_broadcast.R

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717

1818
context("broadcast variables")
1919

20-
# Ensure Spark is installed
21-
sparkCheckInstall()
22-
2320
# JavaSparkContext handle
2421
sparkSession <- sparkR.session(enableHiveSupport = FALSE)
2522
sc <- callJStatic("org.apache.spark.sql.api.r.SQLUtils", "getJavaSparkContext", sparkSession)

R/pkg/inst/tests/testthat/test_context.R

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717

1818
context("test functions in sparkR.R")
1919

20-
# Ensure Spark is installed
21-
sparkCheckInstall()
22-
2320
test_that("Check masked functions", {
2421
# Check that we are not masking any new function from base, stats, testthat unexpectedly
2522
# NOTE: We should avoid adding entries to *namesOfMaskedCompletely* as masked functions make it

R/pkg/inst/tests/testthat/test_includePackage.R

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717

1818
context("include R packages")
1919

20-
# Ensure Spark is installed
21-
sparkCheckInstall()
22-
2320
# JavaSparkContext handle
2421
sparkSession <- sparkR.session(enableHiveSupport = FALSE)
2522
sc <- callJStatic("org.apache.spark.sql.api.r.SQLUtils", "getJavaSparkContext", sparkSession)

R/pkg/inst/tests/testthat/test_jvm_api.R

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717

1818
context("JVM API")
1919

20-
# Ensure Spark is installed
21-
sparkCheckInstall()
22-
2320
sparkSession <- sparkR.session(enableHiveSupport = FALSE)
2421

2522
test_that("Create and call methods on object", {

R/pkg/inst/tests/testthat/test_mllib_classification.R

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ library(testthat)
1919

2020
context("MLlib classification algorithms, except for tree-based algorithms")
2121

22-
# Ensure Spark is installed
23-
sparkCheckInstall()
24-
2522
# Tests for MLlib classification algorithms in SparkR
2623
sparkSession <- sparkR.session(enableHiveSupport = FALSE)
2724

0 commit comments

Comments
 (0)