Managing R Packages
R includes a large number of additional packages that may be installed separately from the main R installation. An alphabetical list of R packages and their descriptions may be found at the following URL:
http://cran.r-project.org/web/packages/available_packages_by_name.html.
Listing Available Packages
To list the available R packages, use the available.packages() function from an R console window. You will need to select a mirror site from which to retrieve the package details. The following command lists details for the first five available packages on the selected mirror site:
> p <- available.packages()
> p[1:5,]
A3
ABCExtremes
"ABCExtremes" "1.0"
ABCoptim
ABCp2
ACCLMA
A3
ABCExtremes
NA
ABCoptim
ABCp2
ACCLMA
A3
ABCExtremes "http://cran.ma.imperial.ac.uk/bin/windows/contrib/3.1"
ABCoptim
ABCp2
ACCLMA
Listing Installed Packages
To list the R packages that are currently installed, use the installed.packages() function from an R console window as follows. The following example lists details for the first five installed packages:
> i <- installed.packages()
> i[1:5,]
base
boot
class
cluster
codetools
"codetools" "C:/Program Files/R/R-3.1.2/library" "0.2-9"
base
boot
class
cluster
codetools
"GPL"
Installing a Package
To install a package, use the install.packages() function from an R console window as follows:
> install.packages("ggplot2")
trying URL 'http://cran.ma.imperial.ac.uk/bin/windows/contrib/3.1/ggplot2_1.0.0.zip'
Content type 'application/zip' length 2675344 bytes (2.6 Mb)
opened URL
downloaded 2.6 Mb
package ‘ggplot2’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
To specify a particular mirror site, use the ‘repos’ parameter as follows:
> install.packages("ggplot2", repos="http://cran.us.r-project.org")
trying URL 'http://cran.us.r-project.org/bin/windows/contrib/3.1/ggplot2_1.0.0.zip'
Content type 'application/zip' length 2675344 bytes (2.6 Mb)
opened URL
downloaded 2.6 Mb
package ‘ggplot2’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
Determining Whether a Package is Installed
To determine whether a particular package is installed, use the installed.packages() and is.element() functions as follows:
> i <- installed.packages()
> packages <- i[,1]
> is.element("ggplot2", packages)
[1] TRUE
Removing a Package
To remove an installed R package, use the remove.packages() function as follows:
> remove.packages("ggplot2")
Removing package from ‘C:/Program Files/R/R-3.1.2/library’
(as ‘lib’ is unspecified)