Skip to content

Commit 06bf250

Browse files
committed
Merge pull request apache#173 from shivaram/windows-space-fix
[SPARKR-200][SPARKR-149] Fix path, classpath separator for Windows
2 parents 17eda4c + 06d99f0 commit 06bf250

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

pkg/R/sparkR.R

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ assemblyJarName <- "sparkr-assembly-0.1.jar"
44

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

109
.sparkREnv$libname <- libname
@@ -98,9 +97,19 @@ sparkR.init <- function(
9897
}
9998

10099
sparkMem <- Sys.getenv("SPARK_MEM", "512m")
101-
jars <- c(as.character(.sparkREnv$assemblyJarPath), as.character(sparkJars))
102-
103-
cp <- paste0(jars, collapse = ":")
100+
jars <- suppressWarnings(
101+
normalizePath(c(as.character(.sparkREnv$assemblyJarPath), as.character(sparkJars))))
102+
103+
# Classpath separator is ";" on Windows
104+
# URI needs four /// as from http://stackoverflow.com/a/18522792
105+
if (.Platform$OS.type == "unix") {
106+
collapseChar <- ":"
107+
uriSep <- "//"
108+
} else {
109+
collapseChar <- ";"
110+
uriSep <- "////"
111+
}
112+
cp <- paste0(jars, collapse = collapseChar)
104113

105114
yarn_conf_dir <- Sys.getenv("YARN_CONF_DIR", "")
106115
if (yarn_conf_dir != "") {
@@ -136,7 +145,7 @@ sparkR.init <- function(
136145
}
137146

138147
nonEmptyJars <- Filter(function(x) { x != "" }, jars)
139-
localJarPaths <- sapply(nonEmptyJars, function(j) { paste("file://", j, sep = "") })
148+
localJarPaths <- sapply(nonEmptyJars, function(j) { utils::URLencode(paste("file:", uriSep, j, sep = "")) })
140149

141150
assign(
142151
".sparkRjsc",

pkg/R/sparkRClient.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ launchBackend <- function(
3535
} else {
3636
java_bin <- java_bin_name
3737
}
38+
# Quote the classpath to make sure it handles spaces on Windows
39+
classPath <- shQuote(classPath)
3840
combinedArgs <- paste(javaOpts, "-cp", classPath, mainClass, args, sep = " ")
3941
cat("Launching java with command ", java_bin, " ", combinedArgs, "\n")
4042
invisible(system2(java_bin, combinedArgs, wait = F))

0 commit comments

Comments
 (0)