How to use R packages from GitHub

By | April 21, 2014

Update: The following R commands will install a package directly from GitHub to R:

> if (!require("devtools"))
> devtools::install_github("YYY/ZZZ")

where YYY is the GitHub username and ZZZ is the package name. For example to install TStools use:

> devtools::install_github("trnnick/TStools")

This makes the process described below unnecessary, however if you want the ‘full’ story read on!

I typically use RStudio in Windows when I code in R, so I will give my examples using that. However this is not crucial for the process, as long as you have some basic knowledge of building packages.

Step 1. Download the files from GitHub

I will first save the files locally. I will be using TStools for this example. At the GitHub page you will see at the bottom-right corner a Download ZIP button. Use that to get a full copy of the directory.


Unzip the contents of the file in a temporary directory.

Step 2. Get Rtools if you don’t have it already

Rtools is a collection of resources for building R under Microsoft Windows. If you have built a package in the past chances are that Rtools is already installed. If you don’t have it then you can get it here. Install it and proceed to the next step.

Step 3. Create a new project in R

In RStudio go to File -> New Project


In the new window select Existing Directory and browse to the folder you unzip the file you downloaded from Github. Drill down until you see the R subdirectory and press Select Folder.


and then click Create Project.

Step 4. Build the package

With the project loaded all that you need to do now is click on Build & Reload in the Build tab. This is typically on the top-left of your screen. Rstudio will now build the package and it will add it to your package list.


If you can see the tabs Environment and History, but not Build then the project is not loaded or something went wrong in the project creation. Repeat step 3 or try looking for the project file in the folder you unzipped the files from GitHub. If there is an .Rproj file you should be able to load it by going to File -> Open Project in the RStudio menu.

Step 5. Close project

The last thing you need to do is go to File -> Close Project in RStudio menu. The package you downloaded from GitHub is now ready to use. You can now delete the temporary directory, including the project files.

Of course there are many different ways to do this process. Here I highlighted one of the simplest ones (I think!).

3 thoughts on “How to use R packages from GitHub

  1. Pingback: دانلود domaintools - آموزشکده به داده

  2. Paulo Pereira

    Hey, I have tried to install TStools, but I got this error.
    ERROR: dependencies ‘smooth’, ‘MAPA’ are not available for package ‘TStools’
    I tried to install smooth and mapa packages, then I try to install the TStools again, but I still get the same error. How can I solve it? Thanks!

    1. Nikos Post author

      Hi Paulo,
      I really do not have any good ideas on this. I guess removing TStools completely and trying again should do it. For me typically when I install any dependencies things seem to work just fine. Make sure that you can load MAPA and smooth on there own and that they do not give any errors.


Leave a Reply

Your email address will not be published. Required fields are marked *