You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by we...@apache.org on 2021/08/11 19:54:53 UTC
[arrow-cookbook] branch main updated: #13 install latest release
(#20)
This is an automated email from the ASF dual-hosted git repository.
westonpace pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-cookbook.git
The following commit(s) were added to refs/heads/main by this push:
new 02e2eaf #13 install latest release (#20)
02e2eaf is described below
commit 02e2eafdf6abcdfccfbf91aad1af1acb12253610
Author: Nic <th...@gmail.com>
AuthorDate: Wed Aug 11 19:54:47 2021 +0000
#13 install latest release (#20)
* install latest release
* Add Apache license, and simplify non-release builds for now
* Refactor and style code
* Fix typo
* Install binaries for dependencies too
* Run styler and update install_arrow_version logic to have better defaults
* Fix issue with NA var
* Less ambigous CI
* Got mixed up with RSPM having Linux binaries
* Typofix
* For loops aren't illegal
* Add issue number to TODO
* test empty commit
---
r/scripts/install_dependencies.R | 90 ++++++++++++++++++++++++++++++----------
1 file changed, 67 insertions(+), 23 deletions(-)
diff --git a/r/scripts/install_dependencies.R b/r/scripts/install_dependencies.R
index d7aef73..d8dfb51 100644
--- a/r/scripts/install_dependencies.R
+++ b/r/scripts/install_dependencies.R
@@ -1,41 +1,85 @@
+# 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.
+
+# Set the version of Arrow to build based on command line arguments
args <- commandArgs(trailingOnly = TRUE)
-# get arguments used to run this script
-if (length(args) == 0) {
- build_version = "latest"
-} else {
+if (length(args) > 0) {
build_version <- package_version(args[1])
+} else {
+ build_version <- package_version(available.packages()["arrow", ]["Version"])
}
-# get installed version of a package
-get_installed_version <- function(pkg){
+#' Get installed version of a package
+#'
+#' @param pkg Package name, character
+#' @return Package version number, or 0.0.0 if not installed.
+get_installed_version <- function(pkg) {
tryCatch(
packageVersion(pkg),
error = function(e) {
- return(structure(list(c(0L, 0L, 0L)), class = c("package_version", "numeric_version")))
+ return(
+ structure(
+ list(
+ c(0L, 0L, 0L)
+ ),
+ class = c("package_version", "numeric_version")
+ )
+ )
}
)
}
-# install dependencies if not installed
-load_package <- function(pkg_name){
- if (!require(pkg_name, character.only = TRUE)) {
- install.packages(pkg_name)
- }
- library(pkg_name, character.only = TRUE)
+#' Load package, installing it first if not already installed
+#'
+#' @param pkg Package name, character.
+load_package <- function(pkg) {
+ if (!suppressWarnings(suppressMessages(require(pkg, character.only = TRUE)))) {
+ install.packages(pkg)
+ }
+ library(pkg, character.only = TRUE)
}
-dependencies <- c("testthat", "bookdown", "knitr", "purrr", "remotes", "dplyr")
-
-lapply(dependencies, load_package)
+#' Install a specific version of the Arrow R package
+#'
+#' @param version_to_install The version to install. Default is latest CRAN version.
+install_arrow_version <- function(version_to_install) {
-# check version of Arrow installed, and install correct one
-if (!inherits(build_version, "package_version") && build_version == "latest") {
- install.packages("arrow", repos = c("https://arrow-r-nightly.s3.amazonaws.com", getOption("repos")))
-} else {
+ # TODO: refactor this to get the latest available version on the nightlies
+ # given we set NOT_CRAN = TRUE (#29)
+ latest_release <- package_version(available.packages()["arrow", ]["Version"])
installed_version <- get_installed_version("arrow")
- if (installed_version != build_version) {
- pkg_url <- paste0("https://cran.r-project.org/src/contrib/Archive/arrow/arrow_", build_version, ".tar.gz")
- install.packages(pkg_url, repos = NULL, type = "source")
+
+ # Only install the latest released version if it's not already installed
+ if (version_to_install == latest_release && installed_version != latest_release) {
+ Sys.setenv(NOT_CRAN = TRUE)
+ install.packages("arrow")
+ # Otherwise install the build version specified if not already installed
+ # TODO: refactor this to install the specific version from the nightlies if
+ # a binary is available (#29)
+ } else if (installed_version != version_to_install) {
+ remotes::install_version("arrow", version = version_to_install)
}
}
+
+dependencies <- c("testthat", "bookdown", "knitr", "purrr", "remotes", "dplyr")
+
+for (dependency in dependencies) {
+ load_package(dependency)
+}
+
+install_arrow_version(build_version)