Github user mengxr commented on a diff in the pull request:
https://github.com/apache/spark/pull/14258#discussion_r72190507
--- Diff: R/pkg/R/install.R ---
@@ -0,0 +1,155 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# Functions to install Spark in case the user directly downloads SparkR
+# from CRAN.
+
+#' Download and Install Spark Core to Local Directory
+#'
+#' \code{install_spark} downloads and installs Spark to local directory if
+#' it is not found. The Spark version we use is 2.0.0 (preview). Users can
+#' specify a desired Hadoop version, the remote site, and the directory
where
+#' the package is installed locally.
+#'
+#' @param hadoop_version Version of Hadoop to install, 2.4, 2.6,
+#' 2.7 (default) and without
+#' @param mirror_url the base URL of the repositories to use
+#' @param local_dir local directory that Spark is installed to
+#' @return \code{install_spark} returns the local directory
+#' where Spark is found or installed
+#' @rdname install_spark
+#' @name install_spark
+#' @export
+#' @examples
+#'\dontrun{
+#' install_spark()
+#'}
+#' @note install_spark since 2.1.0
+install_spark <- function(hadoop_version = NULL, mirror_url = NULL,
+ local_dir = NULL) {
+ version <- paste0("spark-", packageVersion("SparkR"))
+ hadoop_version <- match.arg(hadoop_version, supported_versions_hadoop())
+ packageName <- ifelse(hadoop_version == "without",
+ paste0(version, "-bin-without-hadoop"),
+ paste0(version, "-bin-hadoop", hadoop_version))
+ if (is.null(local_dir)) {
+ local_dir <- getOption("spark.install.dir", spark_cache_path())
+ } else {
+ local_dir <- normalizePath(local_dir)
+ }
+
+ packageLocalDir <- file.path(local_dir, packageName)
+
+
+ # can use dir.exists(packageLocalDir) under R 3.2.0 or later
+ if (!is.na(file.info(packageLocalDir)$isdir)) {
+ fmt <- "Spark %s for Hadoop %s has been installed."
+ msg <- sprintf(fmt, version, hadoop_version)
+ message(msg)
+ return(invisible(packageLocalDir))
+ }
+
+ packageLocalPath <- paste0(packageLocalDir, ".tgz")
+ tarExists <- file.exists(packageLocalPath)
+
+ if (tarExists) {
+ message("Tar file found. Installing...")
+ } else {
+ if (is.null(mirror_url)) {
+ message("Remote URL not provided. Use Apache default.")
+ mirror_url <- mirror_url_default()
+ }
+
+ version <- "spark-2.0.0-rc4-bin"
+ # When 2.0 released, remove the above line and
+ # change spark-releases to spark in the statement below
+ packageRemotePath <- paste0(
+ file.path(mirror_url, "spark-releases", version, packageName),
".tgz")
+ fmt <- paste("Installing Spark %s for Hadoop %s.",
+ "Downloading from:\n- %s",
+ "Installing to:\n- %s", sep = "\n")
+ msg <- sprintf(fmt, version, hadoop_version, packageRemotePath,
+ packageLocalDir)
+ message(msg)
+
+ fetchFail <- tryCatch(download.file(packageRemotePath,
packageLocalPath),
+ error = function(e) {
+ msg <- paste0("Fetch failed from ",
mirror_url, ".")
+ message(msg)
+ TRUE
+ })
+ if (fetchFail) {
+ message("Try the backup option.")
+ mirror_sites <- tryCatch(read.csv(mirror_url_csv()),
+ error = function(e) stop("No csv file
found."))
+ mirror_url <- mirror_sites$url[1]
+ packageRemotePath <- paste0(file.path(mirror_url, version,
packageName),
+ ".tgz")
+ message(sprintf("Downloading from:\n- %s", packageRemotePath))
+ tryCatch(download.file(packageRemotePath, packageLocalPath),
+ error = function(e) {
+ stop("Download failed. Please provide a valid
mirror_url.")
+ })
+ }
+ }
+
+ untar(tarfile = packageLocalPath, exdir = local_dir)
+ if (!tarExists) {
+ unlink(packageLocalPath)
+ }
+ message("Installation done.")
+ invisible(packageLocalDir)
+}
+
+mirror_url_default <- function() {
+ # change to http://www.apache.org/dyn/closer.lua
+ # when released
+
+ "http://people.apache.org/~pwendell"
+}
+
+supported_versions_hadoop <- function() {
+ c("2.7", "2.6", "2.4", "without")
+}
+
+spark_cache_path <- function() {
+ if (.Platform$OS.type == "windows") {
+ winAppPath <- Sys.getenv("%LOCALAPPDATA%", unset = NA)
+ if (is.null(winAppPath)) {
+ msg <- paste("%LOCALAPPDATA% not found.",
+ "Please define or enter an installation path in
loc_dir.")
+ stop(msg)
+ } else {
+ path <- file.path(winAppPath, "spark", "spark", "Cache")
+ }
+ } else if (.Platform$OS.type == "unix") {
+ if (Sys.info()["sysname"] == "Darwin") {
+ path <- file.path(Sys.getenv("HOME"), "Library/Caches", "spark")
+ } else {
+ path <- file.path(
+ Sys.getenv("XDG_CACHE_HOME", file.path(Sys.getenv("HOME"),
".cache")),
+ "spark")
+ }
+ } else {
+ stop("Unknown OS")
--- End diff --
Include the OS name in the error message.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]