An R package includes a set of functions and datasets. Packages are often developed as supplementary material to books. For instance the MASS package was developed by Venables and Ripley for their book Modern Applied Statistics with S and the car package was developed by John Fox for his book An R and S plus Companion to Applied Regression.

A package is loaded into the current R environment using the library() function. A list of functions and datasets included in a package can be obtained by using the h or help argument of the library function.

library("stats4")# loads the package "stats4"library(h=stats4)# gives help for all functions
data(package="stats4")# gives the list of all available datasets

A package can be detached from the current environment by using the detach() function :

>detach("package:prettyR")

Without any arguments the library() function lists all of the packages currently available to the user. env() (gdata) describe all loaded environments (ie packages). search() gives the list of all loaded packages.

>library()# returns the description of all the packages available on the computer >dir(.libPaths())# returns the name of all the packages available on the computer (quicker than the previous one)>search()> env(unit="MB")

current.packages() (Zelig) show all the required and suggested packages.

> current.packages("sem")

Where are my packages stored ?

The .libPaths() function without arguments prints the library directories

The .libPaths() function with a directory as argument defines a new directory where to store new libraries.

You can write down your own R packages. But, all packages submitted to CRAN (or Bioconductor) must follow specific guidelines, including the folder structure of the package and the other files like DESCRIPTION, NAMESPACE and so on.