Packages

Packages are collections of R functions, data, and compiled code in a well-defined format. The directory where packages are stored is called the library. R comes with a standard set of packages. Others are available for download and installation. Once installed, they have to be loaded into the session to be used.

.libPaths() # get library location
library()   # see all packages installed
search()    # see packages currently loaded

Adding Packages

You can expand the types of analyses you do be adding other packages. A complete list of contributed packages is available from CRAN.

Follow these steps:

  1. Download and install a package (you only need to do this once).
  2. To use the package, invoke the library(package) command to load it into the current session. (You need to do this once in each session, unless you customize your environment to automatically load it each time.)

On MS Windows:

  1. Choose Install Packages from the Packages menu.
  2. Select a CRAN Mirror. (e.g. Norway)
  3. Select a package. (e.g. boot)
  4. Then use the library(package) function to load it for use. (e.g. library(boot))

On Linux:

  1. Download the package of interest as a compressed file.
  2. At the command prompt, install it using
    R CMD INSTALL [options] [l-lib] pkgs
  3. Use the library(package) function within R to load it for use in the session.

Creating Your Own Packages

To create your own packages look at Writing R Extensions (the definitive guide), Leisch's Creating R Packages: A Tutorial, and Rossi's Making R packages Under Windows: A Tutorial.