Install R packages from Github through proxy

The easiest way to install an R package is from R-Cran. However, as the number of R users is growing up very fast, many developers are contribute to R community through Github. And the standard way to install from Github is to use devtools package with install_github() command.

In many organization, especially financial organization like banking industry, sometimes it is very hard to install an R package from CRAN or Github due to security process. So, in this post I will share with you 2 ways to install an R package via proxy

##Method 1: Using downloader package

In this method, the only thing that you need to change is the Github repository of the R package needed to be installed.

For example, if you want to install package easyRFM from Github with the following link: github.com/hoxo-m/easyRFM, you can easily install with the following codes:

#Step 1: Install downloader from CRAN
install.packages("downloader")
library(downloader)

#Step 2: Download R package from Github in format .tar.gz
download("https://github.com/hoxo-m/easyRFM/archive/master.tar.gz",
         "easyRFM.tar.gz")

#Step 3: Install from source
install.packages("easyRFM.tar.gz", repos = NULL, type = "source")

##Method 2: Using httr package to modify your proxy

In this method, you can modify your proxy using httr package. To modify your proxy, the key function is set_config.

httr::set_config(use_proxy("your_proxy:your_port"))

For instance, if your proxy is 11.36.22.12 & your port is 8080, you can modify your proxy as follows:

#Step 1: Call httr & devtools
library(httr)
library(devtools)

#Step 2: Modify proxy
set_config(use_proxy("11.36.22.12:8080"))

#Step 3: Install package directly from Github
install_github("rstats-db/odbc")

#Step 4: Reset your proxy if needed
reset_config()

Two methods above help me a lot to install R packages, specially from Github. Hope that it will help you also to make your life easier!

Anh Hoang Duc
Anh Hoang Duc
Business Analytics professional

.

comments powered by Disqus

Related