Update: The following R commands will install a package directly from GitHub to R:
> if (!require("devtools")) install.packages("devtools") > devtools::install_github("YYY/ZZZ")
where YYY is the GitHub username and ZZZ is the package name. For example to install TStools use:
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!).