Often, important R packages aren’t on CRAN – they’re on GitHub. This guide shows you how to install an R package from GitHub in R or RStudio in three simple steps, using the devtools
package. You’ll also learn tips for troubleshooting and alternatives.
As an example, this post illustrates how to install the flipPlots package to create Sankey diagrams (click here for some example code).
How to install R packages from GitHub?
Step 1: Install the devtools package
To install a R package, start by installing the devtools package. The best way to do this is from CRAN, by typing:
install.packages("devtools")
Step 2: Install the package of interest from GitHub
Install the package of interest from GitHub using the following code, where you need to remember to list both the author and the name of the package (in GitHub jargon, the package is the repo, which is short for repository). In this example, we are installing the flipPlots package created by Displayr.
library(devtools) install_github("Displayr/flipPlots")
Step 3: Load the package
library(flipPlots)
Note: this process works the same on Windows, Mac, and Linux. On Windows you may need Rtools; on Mac, Xcode.
How to Install R Packages from GitHub in RStudio
In RStudio, open the Console and run the same commands shown above. The process is identical to using R directly – just copy the install_github("user/repo")
line into your Console.
Installing GitHub packages into Displayr
Many GitHub packages, such as flipPlots, are already installed in Displayr, so we've done the work for you! If you need any additional packages installed, please reach out to [email protected].
FAQs: Installing R Packages from GitHub
1. How do I install an R package from GitHub in RStudio?
Open the Console and run the same commands as in base R:
install.packages("devtools")
devtools::install_github("user/repo")
No special RStudio steps are required.
2. Do I need to install devtools
every time?
No—install it once. In future sessions either run library(devtools)
or use the prefix devtools::install_github()
.
3. Can I use remotes
instead of devtools
?
Yes. It’s a lighter alternative:
install.packages("remotes")
remotes::install_github("user/repo")
4. Why is install_github()
failing?
Common causes: devtools/remotes not installed/loaded, missing build tools (Rtools on Windows, Xcode CLT on macOS), typo in user/repo
, private repo/auth issues, or network/proxy restrictions.
5. How do I install a specific branch, tag, or commit?
devtools::install_github("user/repo@branchname")
devtools::install_github("user/[email protected]")
devtools::install_github("user/repo@<commit-sha>")
6. How do I update a package installed from GitHub?
Re-run install_github("user/repo")
to get the latest, or use remotes::update_packages()
.
7. Do I need extra tools on Windows or macOS?
Often yes for packages built from source: install Rtools on Windows, Xcode Command Line Tools on macOS. Linux users may need build essentials (e.g., gcc
, make
).
8. Is it safe to install packages from GitHub?
GitHub packages aren’t CRAN-vetted. Prefer reputable repos, review READMEs/issues, and pin tags or SHAs for reproducibility.
9. Does this work on Windows, macOS, and Linux?
Yes—the commands are the same. Platform differences mainly involve required build tools (see Q7).
10. How can I check that the package was installed correctly?
library(pkgname)
packageVer
Ready to install your R package of choice from GitHub in Displayr? Get started below.[/vc_column_text]
[/vc_column][/vc_row]