Installing and using packages

Problem

You want to do install and use a package.

Solution

If you are using a GUI for R, there is likely a menu-driven way of installing packages. This is how to do it from the command line:

  1. install.packages('reshape2')

In each new R session where you use the package, you will have to load it:

  1. library(reshape2)

If you use the package in a script, put this line in the script.

To update all your installed packages to the latest versions available:

  1. update.packages()

If you are using R on Linux, some of the R packages may be installed at the system level by the root user, and can’t be updated this way, since you won’t haver permission to overwrite them.