R Language Installing packages Download and install packages from repositories


Packages are collections of R functions, data, and compiled code in a well-defined format. Public (and private) repositories are used to host collections of R packages. The largest collection of R packages is available from CRAN.

Using CRAN

A package can be installed from CRAN using following code:


Where "dplyr" is referred to as a character vector.

More than one packages can be installed in one go by using the combine function c() and passing a series of character vector of package names:

install.packages(c("dplyr", "tidyr", "ggplot2"))

In some cases, install.packages may prompt for a CRAN mirror or fail, depending on the value of getOption("repos"). To prevent this, specify a CRAN mirror as repos argument:

install.packages("dplyr", repos = "https://cloud.r-project.org/") 

Using the repos argument it is also possible to install from other repositories. For complete information about all the available options, run ?install.packages.

Most packages require functions, which were implemented in other packages (e.g. the package data.table). In order to install a package (or multiple packages) with all the packages, which are used by this given package, the argument dependencies should be set to TRUE):

install.packages("data.table", dependencies = TRUE)

Using Bioconductor

Bioconductor hosts a substantial collection of packages related to Bioinformatics. They provide their own package management centred around the biocLite function:

    ## Try http:// if https:// URLs are not supported

By default this installs a subset of packages that provide the most commonly used functionality. Specific packages can be installed by passing a vector of package names. For example, to install RImmPort from Bioconductor: