R Packages

1. From CRAN

Install these packages from CRAN (using the package manager GUI in R/RStudio, or install.packages()). If you're using the GUI, always check the "install dependencies" box.

1.1. Hadleyverse

Hadley Wickham has done more than just about anyone to make R more powerful, expressive, and easy to use for common data analysis tasks. These are just the packages that are most often useful for the kind of stuff we do, but if there's a task you are frustrated by in R, Hadley's probably written a package to make it easier.

1.2. Everything else

1.3. For heavy Bayesian lifting

You don't need these unless you want to do any kind of Bayesian modeling.

A quicker way to do it is to copy and paste the following line at your R prompt:


tidyverse includes: broom, dplyr, forcats, ggplot2, haven, httr, hms, jsonlite, lubridate, magrittr, modelr, purrr, readr, readxl, stringr, tibble, rvest, tidyr, xml2

2. From github (source)

Sometimes a package isn't available on CRAN (usually temporarily) as a binary for your platform. Or it's not on CRAN at all, but is hosted on Github or Bitbucket or something. In both of these cases, you'll need to install from source.

2.1. One-time set up: developer tools

If you need to build a package from source, make sure you have the developer tools for your OS installed. For MacOS, they are available on the App Store if you have the most up-to-date version of MacOS, or from the developer site (where you'll need to register for a free account first) if you have anything less than the most up-to-date version. I think You only need to install the "Command Line Tools", not XCode itself.

You may also need Fortran, which you can install very easily using homebrew, e.g., brew install gfortran (recommended) or from the MacOS tools page on CRAN. This StackExchange answer is a good discussion of the pros and cons of various ways to install Fortran on MacOS.

The last thing you'll need is to install devtools with install.packages('devtools') in R.

2.2. Installing packages from source

Let's say I want to install dplyr from the github source. I google it and find that it's hosted at http://github.com/hadley/dplyr. Then, in R:


Piece of cake.

devtools includes a whole family of functions for installing source from pretty much anywhere you might find it. If, for instance, you want to install from the source archive on CRAN (e.g., http://cran.r-project.org/src/contrib/dplyr_0.4.1.tar.gz), you can use the install_url command:


3. From Bioconductor

I have no idea whether this is still necessary but I'm leaving it here for posterity's sake — Dave

When you install the packages above, you may get this warning: Warning: dependencies ‘marray’, ‘affy’, ‘Biobase’, ‘Rgraphviz’, ‘’ are not available. To fix it, install the standard packages from Bioconductor by doing the following at the R prompt:


adjusting lib as appropriate for your OS. The example above is for Mac OS X. For Windows use:

biocLite(lib='C:\\Program Files\\R\\R-2.11.1\\library')

adjusting the version number as appropriate. (n.b. You must have Administrator privileges to install anything under C:/Program Files/)

HlpLab: Rpackages (last edited 2017-05-02 14:41:12 by AndrewWatts)

MoinMoin Appliance - Powered by TurnKey Linux