Skip to content

Instantly share code, notes, and snippets.

@wrathematics
Created March 1, 2021 15:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wrathematics/ccf6bf366279e099563e69e56b4fde59 to your computer and use it in GitHub Desktop.
Save wrathematics/ccf6bf366279e099563e69e56b4fde59 to your computer and use it in GitHub Desktop.
Install (from) GitHub With Sub-Modules
#' ighwsm
#' Install (from) GitHub With Sub-Modules. Use when
#' \code{remotes::install_github()} fails.
#'
#' @details
#' Wrapper around \code{system()}.
#'
#' @param repo
#' GH repo of the usual form: \code{name/project}.
#' @param save_clone
#' Should the \code{git clone} tree be saved?
#' @param verbose
#' Should clone/install info be printed?
#' @param install_args
#' Additional arguments passed to \code{R CMD INSTALL}.
ighwsm = function(repo, save_clone=FALSE, verbose=FALSE, install_args="")
{
verbose = isTRUE(verbose)
path = paste0("/tmp/", basename(repo))
if (dir.exists(path))
{
if (verbose)
cat(paste0("* dir already exists at path=", path, " skipping\n"))
}
else
{
if (verbose)
cat(paste0("* cloning into path=", path, "\n"))
cmd = paste0("cd /tmp && git clone --recurse-submodules https://github.com/", repo, ".git")
system(cmd, ignore.stdout=verbose)
}
if (verbose)
cat(paste0("* cloning into path=", path, "\n"))
cmd = paste("R CMD INSTALL", install_args, path)
ret = system(cmd, ignore.stdout=!verbose, ignore.stderr=!verbose)
if (!isTRUE(save_clone))
unlink(path)
invisible(!as.logical(ret))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment