In R, a package is a collection of a set of functions, associated data sets and related documents like manuals and tutorials. A given package is generally aimed at a particular type of analysis. For example, the stats package contains codes for statistical analysis, graphics package has scripts for graphics.
The R installation comes with a set of basic packages. In addition, thousands of packages for various analysis are kept at external repositories. These external packages can be downloaded from R prompt via internet. The downloaded package will be placed inside a directory inside R the installation. Once downloded, they can be included in R environment and used. We need internet connection for these downloads.
From R prompt, the command
will list the directories where the downloded packages are installed.> .libPaths()
To get a list and small description of all the R packages installed in the system, call the list() function:
To install an external R package, use install.packages() function. For example, to install the package called cluster , type
A package needs to be installed only once. The package can be included in a R script by calling library() function with package name as a string argument:
After the above call, all the functions inside library "cluster" will be availble inside the script.
The library function can also prints information on a given package :
The data sets inside a package can be listed by data() function:
A package attached by the library() can be removed by the detach() function:
To display all the packages available in the repositories,
In order to update all the installed packages with the newest version from repositories,
The above two functions will prompt the user to choose a CRAN mirror site from the list of options.