To install packages directly from GitHub use the devtools
package:
library(devtools)
install_github("authorName/repositoryName")
To install ggplot2
from github:
devtools::install_github("tidyverse/ggplot2")
The above command will install the version of ggplot2
that corresponds to the master branch. To install from a different branch of a repository use the ref
argument to provide the name of the branch. For example, the following command will install the dev_general
branch of the googleway
package.
devtools::install_github("SymbolixAU/googleway", ref = "dev_general")
Another option is to use the ghit
package. It provides a lightweight alternative for installing packages from github:
install.packages("ghit")
ghit::install_github("google/CausalImpact")
To install a package that is in a private repository on Github, generate a personal access token at http://www.github.com/settings/tokens/ (See ?install_github for documentation on the same). Follow these steps:
install.packages(c("curl", "httr"))
config = httr::config(ssl_verifypeer = FALSE)
install.packages("RCurl")
options(RCurlOptions = c(getOption("RCurlOptions"),ssl.verifypeer = FALSE, ssl.verifyhost = FALSE ) )
getOption("RCurlOptions")
You should see the following:
ssl.verifypeer ssl.verifyhost
FALSE FALSE
library(httr)
set_config(config(ssl_verifypeer = 0L))
This prevents the common error: "Peer certificate cannot be authenticated with given CA certificates"
Finally, use the following command to install your package seamlessly
install_github("username/package_name",auth_token="abc")
Alternatively, set an environment variable GITHUB_PAT
, using
Sys.setenv(GITHUB_PAT = "access_token")
devtools::install_github("organisation/package_name")
The PAT generated in Github is only visible once, i.e., when created initially, so its prudent to save that token in .Rprofile
. This is also helpful if the organisation has many private repositories.