westonpace commented on a change in pull request #20:
URL: https://github.com/apache/arrow-cookbook/pull/20#discussion_r686239974



##########
File path: 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
+  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

Review comment:
       Nit, can you add a GH issue for this and reference it as part of the 
todo, `TODO(#17)` or something like that.
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to