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
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:
- Download and install a package (you only need to do this once).
- 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:
- Choose Install Packages from the Packages menu.
- Select a CRAN Mirror. (e.g. Norway)
- Select a package. (e.g. boot)
- Then use the library(package) function to load it for use. (e.g. library(boot))
- Download the package of interest as a compressed file.
- At the command prompt, install it using
R CMD INSTALL [options] [l-lib] pkgs
- Use the library(package) function within R to load it for use in the session.