From 273f814200d6c0dedbf1a1d006f706d1a2af2bb9 Mon Sep 17 00:00:00 2001 From: Conor Anderson Date: Thu, 11 Oct 2018 22:08:13 -0400 Subject: [PATCH] Fix install_senamhiR.R [skip ci] --- install_senamhiR.R | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/install_senamhiR.R b/install_senamhiR.R index 9cdbf00..14f11d3 100644 --- a/install_senamhiR.R +++ b/install_senamhiR.R @@ -1,3 +1,22 @@ +install_via_remotes <- function() { + print("Installing using the remotes package via install.github.me") + source("https://install-github.me/r-lib/remotes") + remotes::install_gitlab("ConorIA/senamhiR") +} + +install_fallback <- function() { + print("Falling back to install via devtools") + if("devtools" %in% rownames(installed.packages()) == FALSE) { + install.packages("devtools", repos = "https://cloud.r-project.org") + } + url <- "https://gitlab.com/ConorIA/senamhiR/-/archive/master/senamhiR-master.tar.gz" + f <- tempfile() + d <- tempdir() + download.file(url, f) + untar(f, exdir = d) + devtools::install(file.path(d, "senamhiR-master"), dependencies = TRUE) +} + cat("##### PSA ##### \n You are about to run remote code! It is always a good idea to review remote \ code before running, as a malicious actor could use a script like this to do \ @@ -6,8 +25,15 @@ In this case, we are going to install the remotes package and use it to install\ senamhiR.\n\n") if (readline("Would you like to proceed? (y/N)") %in% c("Y", "y")) { - source("https://install-github.me/r-lib/remotes") - remotes::install_gitlab("ConorIA/senamhiR") + result <- try(install_via_remotes()) + if(inherits(result, "try-error")) { + warning(paste("There was an issue installing with remotes.", + "Falling back to tarball install.")) + result <- try(install_fallback()) + if(inherits(result, "try-error")) { + stop("We encountered an error during install. Sorry about that!") + } + } } else { stop("Review the remote code and try again.") -} +} \ No newline at end of file