Installing R Packages Not Hosted on CRAN

Note: The purpose of this Help Article is to provide general guidance. DataCamp does not offer support for installing packages externally.

Sometimes, you will take a course on DataCamp and learn how to use a new R package. However, once you switch to your local environment and use the `install.packages()` command to get the package, you may realize that you can't install the package locally. The most plausible reason is that it is not hosted on CRAN. CRAN (Comprehensive R Archive Network) has very strict requirements, which can make listing a package a slow process. This doesn't necessarily mean that the package isn't functional, stable, or can't be used.

Let's take a concrete example. The DataCamp course Financial Trading in R uses the R quantstrat package (at the time this article was written, quantstrat was not listed on CRAN). What you need to do then is install it directly from the GitHub repo where it's hosted.

To do this, you first need to install `devtools`, which will let you use the `install_github()` command and then get the package you need by specifying the username and the repo where the package is hosted. To install quantstrat, you would execute the snippet below:

install_github("braverock/blotter") # dependency

In general, it's good practice to check the CRAN list of available packages to see if the package you're looking for is listed or not. Just type Cmd + F on a Mac or Ctrl + F on Windows, and enter the name of the package you're looking for. If it shows 0, then it's not listed.



Then you can check the R-Forge page for the package (here is the one for quantstrat). If the status reads "Failed to build", then it means that the package does not meet the CRAN Repository Policy and is therefore not available from there.


In this case, you need to use the same process as shown above for quantstrat:

  • make sure devtools is installed on your local machine (`install.packages("devtools")`)
  • load devtools (`require(devtools)`)
  • install the dependencies that the package you want needs (`install_github("username/dependency_repo")`)
  • install the package you want (`install_github("username/package_repo")`)