[R-pkg-devel] install from github

Berry Boessenkool berryboessenkool at hotmail.com
Thu Dec 3 09:40:12 CET 2015





Hi,

is someone aware of a way to easily install a package hosted on github without using devtools::install_github?
Does anyone else ever need to avoid devtools?
Would something doing that be worth a package on CRAN?
Optional if no,yes,yes: Is my basic idea below any good at all?

Thanks ahead,
Berry, Potsdam, Germany

Details:

devtools has so many dependencies that it takes quite some time to install on old computers or with slow internet. Not suitable for a quick demo in the R course I'm teaching, which I found out the hard way (thinking R had hung up, I terminated it, crashing Rstudio in the proces...).
Not finding anything and happy to postpone actual work, I wrote some (very!) basic code. I doubt it works across platforms and situations. I guess I'm doing useless stuff, but I had fun and learned a few new things...


instgithub <- function(
   pk, # "user/package"
   cleanup=TRUE, # remove downloaded zipfile and folder with source code
   ...) # Further arguments passed to install.packages, untested so far
{
pkn <- strsplit(pk, "/")[[1]][2] # package name part
download.file(url=paste0("https://github.com/",pk,"/archive/master.zip"),
              destfile=paste0(pkn,".zip"))
unzip(paste0(pkn,".zip"))
file.rename(paste0(pkn,"-master"), pkn)
# Dependencies - really not elegant at all!
deps <- read.dcf(paste0(pkn, "/DESCRIPTION"), fields="Imports")
deps <- strsplit(deps, ", ")[[1]]
deps <- sapply(strsplit(deps, " ", fixed=T), "[", 1) # remove version restrictions
deps <- deps[!deps %in% rownames(installed.packages())] # install only new packages
# install dependencies
dummy <- lapply(na.omit(deps), install.packages, ...)
# actually install the package itself:
install.packages(pkn, repos=NULL, type="source", ...)
# clean up:
if(cleanup)
  {
  unlink(pkn, recursive=TRUE)
  unlink(paste0(pkn,".zip"))
  }
}

# example test cases, work fine on windows 7 with current R3.2.2 + write permission at getwd:
if(FALSE){
instgithub(pk="brry/extremeStat")
library(extremeStat)
instgithub("talgalili/installr")
instgithub("hadley/readxl")
}



 		 	   		  
	[[alternative HTML version deleted]]



More information about the R-package-devel mailing list