Skip to content

Commit

Permalink
Make SparkR work on paths with spaces on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
shivaram committed Jan 31, 2015
1 parent 227ee42 commit 73430c6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
21 changes: 16 additions & 5 deletions pkg/R/sparkR.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ assemblyJarName <- "sparkr-assembly-0.1.jar"

sparkR.onLoad <- function(libname, pkgname) {
assemblyJarPath <- paste(libname, "/SparkR/", assemblyJarName, sep = "")
assemblyJarPath <- gsub(" ", "\\ ", assemblyJarPath, fixed = T)
packageStartupMessage("[SparkR] Initializing with classpath ", assemblyJarPath, "\n")

.sparkREnv$libname <- libname
Expand Down Expand Up @@ -87,9 +86,16 @@ sparkR.init <- function(
}

sparkMem <- Sys.getenv("SPARK_MEM", "512m")
jars <- c(as.character(.sparkREnv$assemblyJarPath), as.character(sparkJars))

cp <- paste0(jars, collapse = ":")
jars <- suppressWarnings(
normalizePath(c(as.character(.sparkREnv$assemblyJarPath), as.character(sparkJars))))

# Classpath separator is ";" on Windows
if (.Platform$OS.type == "unix") {
collapseChar <- ":"
} else {
collapseChar <- ";"
}
cp <- paste0(jars, collapse = collapseChar)

yarn_conf_dir <- Sys.getenv("YARN_CONF_DIR", "")
if (yarn_conf_dir != "") {
Expand Down Expand Up @@ -125,7 +131,12 @@ sparkR.init <- function(
}

nonEmptyJars <- Filter(function(x) { x != "" }, jars)
localJarPaths <- sapply(nonEmptyJars, function(j) { paste("file://", j, sep = "") })
# URIs don't work very well on Windows, so just use paths.
localJarPaths <- if (.Platform$OS.type == "unix") {
sapply(nonEmptyJars, function(j) { paste("file://", j, sep = "") })
} else {
nonEmptyJars
}

assign(
".sparkRjsc",
Expand Down
2 changes: 2 additions & 0 deletions pkg/R/sparkRClient.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ launchBackend <- function(
} else {
java_bin <- java_bin_name
}
# Quote the classpath to make sure it handles spaces on Windows
classPath <- shQuote(classPath)
combinedArgs <- paste(javaOpts, "-cp", classPath, mainClass, args, sep = " ")
cat("Launching java with command ", java_bin, " ", combinedArgs, "\n")
invisible(system2(java_bin, combinedArgs, wait = F))
Expand Down

0 comments on commit 73430c6

Please sign in to comment.