A Helpful Way to Install R Packages Hosted on GitHub

Provides an helpful way to install packages hosted on GitHub.


Koji MAKIYAMA (@hoxo_m)

A growing number of R packages are created by various people in the world. A part of the cause of it is the devtools package that makes it easy to develop R packages [1]. The devtools package not only facilitates the process to develop R packages but also provides an another way to distribute R packages.

When developers publish R packages that created by them, the CRAN [2] is commonly used. You can install packages that are available on CRAN using install.package(). For example, you can install dplyr package as follows:

install.packages("dplyr")

The devtools package provides install_github() that enables installing packages from GitHub.

library(devtools)
install_github("hadley/dplyr")

Therefore, developers can distribute R packages that are developing on GitHub. In addition, there are some developers that they have no intention to submit to CRAN. For instance, Twitter, Inc. provides AnomalyDetection package on GitHub but they won't submit to CRAN [3]. You can install such packages easily using devtools.

library(devtools)
install_github("twitter/AnomalyDetection")

There is a difference between install.packages() and install_github() in the required argument. install.packages() takes package names, while install_github() needs repository names. It means that when you want to install a package on GitHub you must remember its repository name correctly.

The trouble is that the usernames of GitHub are often hard to remember. Developers consider their package names so that users can understand their functionalities intuitively. However, they often decide username incautiously. For instance, ggfortify is a great package on GitHub, but who created it? What is its username? The answer is sinhrks [4]. It seems to be difficult to remember it.

The githubinstall package provides a way to install packages on GitHub by only their package names just like install.packages().

library(githubinstall)
githubinstall("AnomalyDetection")
Suggestion:
 - twitter/AnomalyDetection  Anomaly Detection with R
Do you want to install the package (Y/n)?  

githubinstall() suggests GitHub repositories from input package names and asks whether you really install it.

Furthermore, you may succeed in installing packages from a faint memory because our package automatically corrects its spelling by fuzzy string search.

githubinstall("AnomaryDetection")
githubinstall("AnomalyDetect")
githubinstall("anomaly-detection")

You can install the githubinstall package from CRAN.

install.packages("githubinstall")

You can also install the package from GitHub.

install.packages("devtools") # if you have not installed "devtools" package
devtools::install_github("hoxo-m/githubinstall")

The source code for githubinstall package is available on GitHub at

  • https://github.com/hoxo-m/githubinstall.

The githubinstall package provides several useful functions.

  • gh_install_packages() or githubinstall()
  • gh_suggest()
  • gh_suggest_username()
  • gh_list_packages()
  • gh_search_packages()
  • gh_show_source()
  • gh_update_package_list()

The functions have common prefix gh. githubinstall() is an alias of gh_install_packages().

To use these functions, first, you should load the package as follows.

library(githubinstall)

gh_install_packages() enables to install packages on GitHub by only package names.

gh_install_packages("AnomalyDetection")
Suggestion:
 - twitter/AnomalyDetection  Anomaly Detection with R
Do you want to install the package (Y/n)?  

The function suggests GitHub repositories. If you type 'Y' or 'y' and press 'Enter' (the default is 'Y'), then installation of the package will begin. The suggestion is made of looking for a list of R packages on GitHub. The list is provided by Gepuro Task Views.

If multiple candidates are found, you can select one of them.

gh_install_packages("cats")
Select a number or, hit 0 to cancel. 
 
1: amurali2/cats      cats
2: danielwilhelm/cats No description or website provided.
3: hilaryparker/cats  An R package for cat-related functions #rcatladies
4: lolibear/cats      No description or website provided.
5: rafalszota/cats    No description or website provided.
6: tahir275/cats      ff
 
Selection: 

githubinstall() is an alias of gh_install_packages().

githubinstall("AnomalyDetection")

A new feature has added.

You can install packages with specifying Git references (branch, tag, commit and pull request).

Developers are divided in policy to manage R packages on GitHub. If a package is going to be developed in "develop" branch, you may want to install the package from the branch.

gh_install_packages() has ref argument to specify Git references. For instance, you can install awaptools from the "develop" branch as follows:

gh_install_packages("awaptools", ref = "develop")

You may sometimes encounter failing to install packages because its repository HEAD is broken. In such case, you can specify a tag or commit to ref. In almost cases, tags are added on an unbroken commit. For instance, you can install densratio from the "v0.0.3" tag as follows:

gh_install_packages("densratio", ref = "v0.0.3")

Even if you cannot find such tags, you can install packages from any commit that is not broken. For instance, you can install densratio from the "e8233e6" commit as follows:

gh_install_packages("densratio", ref = "e8233e6")

Finally, you may find a patch for fixing bugs as a pull request. In such case, you can specify pull requests to ref using github_pull(). For instance, you can install dplyr from the pull request #2058 as follows:

gh_install_packages("dplyr", ref = github_pull("2058"))

gh_install_packages() prompts you to install the suggested packages. But you may just want to know what will be suggestions.

gh_suggest() returns the suggested repository names as a vector.

gh_suggest("AnomalyDetection")
#> [1] "twitter/AnomalyDetection"
gh_suggest("cats")
#>  [1] "amurali2/cats"         "danielwilhelm/cats"   
#>  [3] "davidluizrusso/cats"   "hilaryparker/cats"    
#>  [5] "jonathanelee1993/cats" "lloydlow/cats"        
#>  [7] "lolibear/cats"         "oliviergimenez/cats"  
#>  [9] "rafalszota/cats"       "tahir275/cats"

In addition, gh_suggest_username() is useful when you want to know usernames from a faint memory.

gh_suggest_username("hadly")
#> [1] "hadley"
gh_suggest_username("yuhui")
#> [1] "yihui"

gh_list_packages() returns a list of R package repositories on GitHub as data.frame.

For example, if you want to get the repositories that have been created by hadley, run the following.

hadleyverse <- gh_list_packages(username = "hadley")
head(hadleyverse)
#>   username package_name                                              title
#> 1   hadley   assertthat                     User friendly assertions for R
#> 2   hadley    babynames An R package contain all baby names data from the 
#> 3   hadley    bigrquery          An interface to Google's bigquery from R.
#> 4   hadley     bookdown                                              Watch
#> 5   hadley   clusterfly An R package for visualising high-dimensional clus
#> 6   hadley      decumar                           An alternative to sweave

By using the result, you can install all packages created by hadley.

repos <- with(hadleyverse, paste(username, package_name, sep="/"))
githubinstall(repos) # I have not tried it

gh_search_packages() returns a list of R package repositories on GitHub that their titles contain a given keyword.

For example, if you want to search packages that are relevant to lasso, run the following.

gh_search_packages("lasso")
#>           username     package_name                                  title
#> 1  ChingChuan-Chen             milr  multiple-instance logistic regressi..
#> 2        ManuSetty            SeqGL  SeqGL is a group lasso based algori..
#> 3       YaohuiZeng         biglasso  Big Lasso: Extending Lasso Model Fi..
#> 4      huayingfang          CCLasso  CCLasso: Correlation Inference for ..
#> 5         mlampros FeatureSelection  Feature Selection in R using glmnet..
#> 6             pnnl        glmnetLRC  Lasso and Elastic-Net Logistic Regr..
#> 7       statsmaths         genlasso  Path algorithm for generalized lass..
#> 8       vincent-dk         logitsgl  Fit Logistic Regression with Multi-..
#> 9       vincent-dk             lsgl  Linear Multiple Output Using Sparse..
#> 10      vincent-dk             msgl  High Dimensional Multiclass Classif..
#> 11      vstanislas             GGEE  R Package for the Group Lasso Gene-..
#> 12          zdk123       BatchStARS  R package for Stability Approach to..

gh_show_source() looks for a source code on GitHub for a given function and tries to open the place on your Web browser.

gh_show_source("mutate", repo = "dplyr")

If you have loaded the package that the function belongs to, you can input the function directly.

library(dplyr)
gh_show_source(mutate)

This function may do not work well with Safari.

The githubinstall package uses Gepuro Task Views for getting the list of R packages on GitHub. Gepuro Task Views is crawling the GitHub and updates information every day. The package downloads the list of R packages from Gepuro Task Views each time it was loaded. Thus, you can always use the newest list of packages on a new R session.

However, you may use an R session for a long time. In such case, gh_update_package_list() is useful.

gh_update_package_list() updates the downloaded list of the R packages explicitly.

gh_update_package_list()

News

githubinstall 0.2.0

  • The package does not depend on stringr package. (#25)
  • Fixes some points about English (#21, @nuno-agostinho) (#22, @teramonagi)

githubinstall 0.1.0

  • gh_install_package() gains ref argument to specify Git references (#6).
  • gh_suggest_username() returns "yutannihilation" by passing "yutani" etc (#3, @teramonagi).
  • gh_install_package() changes from asking number (1: Yes, 2: No) to asking [Y/n]. (#5)
  • gh_install_package() records GitHub to the package description (#4).
  • gh_install_package() overwite packages if it already installed (#6).

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("githubinstall")

0.2.1 by Koji Makiyama, 7 months ago


https://github.com/hoxo-m/githubinstall


Report a bug at https://github.com/hoxo-m/githubinstall/issues


Browse source code at https://github.com/cran/githubinstall


Authors: Koji Makiyama [cre, aut], Atsushi Hayakawa [ctb], Shinya Uryu [ctb], Hiroaki Yutani [ctb], Nagi Teramo [ctb]


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports curl, data.table, devtools, httr, jsonlite, utils

Suggests testthat, ggplot2, lubridate, knitr, rmarkdown


Imported by RDocumentation, automagic, yearn.


See at CRAN