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,]

            Package       Version   Priority Depends                          Imports LinkingTo Suggests              Enhances License     

A3          "A3"          "0.9.2"   NA       "R (>= 2.15.0), xtable, pbapply" NA      NA        "randomForest, e1071" NA       "GPL (>= 2)"

ABCExtremes "ABCExtremes" "1.0"     NA       "SpatialExtremes, combinat"      NA      NA        NA                    NA       "GPL-2"     

ABCoptim    "ABCoptim"    "0.13.11" NA       NA                               NA      NA        NA                    NA       "GPL (>= 3)"

ABCp2       "ABCp2"       "1.1"     NA       "MASS"                           NA      NA        NA                    NA       "GPL-2"     

ACCLMA      "ACCLMA"      "1.0"     NA       NA                               NA      NA        NA                    NA       "GPL-2"     

            License_is_FOSS License_restricts_use OS_type Archs MD5sum NeedsCompilation File

A3          NA              NA                    NA      NA    NA     NA               NA  

ABCExtremes NA              NA                    NA      NA    NA     NA               NA  

ABCoptim    NA              NA                    NA      NA    NA     NA               NA  

ABCp2       NA              NA                    NA      NA    NA     NA               NA  

ACCLMA      NA              NA                    NA      NA    NA     NA               NA  

            Repository                                             

A3          "http://cran.ma.imperial.ac.uk/bin/windows/contrib/3.1"

ABCExtremes "http://cran.ma.imperial.ac.uk/bin/windows/contrib/3.1"

ABCoptim    "http://cran.ma.imperial.ac.uk/bin/windows/contrib/3.1"

ABCp2       "http://cran.ma.imperial.ac.uk/bin/windows/contrib/3.1"

ACCLMA      "http://cran.ma.imperial.ac.uk/bin/windows/contrib/3.1"

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,]

          Package     LibPath                              Version  Priority      Depends                         Imports               LinkingTo Suggests         Enhances

base      "base"      "C:/Program Files/R/R-3.1.2/library" "3.1.2"  "base"        NA                              NA                    NA        NA               NA      

boot      "boot"      "C:/Program Files/R/R-3.1.2/library" "1.3-13" "recommended" "R (>= 3.0.0), graphics, stats" NA                    NA        "MASS, survival" NA      

class     "class"     "C:/Program Files/R/R-3.1.2/library" "7.3-11" "recommended" "R (>= 3.0.0), stats, utils"    "MASS"                NA        NA               NA      

cluster   "cluster"   "C:/Program Files/R/R-3.1.2/library" "1.15.3" "recommended" "R (>= 2.12.0), stats, utils"   "graphics, grDevices" NA        "MASS"           NA      

codetools "codetools" "C:/Program Files/R/R-3.1.2/library" "0.2-9"  "recommended" "R (>= 2.1)"                    NA                    NA        NA               NA      

          License           License_is_FOSS License_restricts_use OS_type MD5sum NeedsCompilation Built  

base      "Part of R 3.1.2" NA              NA                    NA      NA     NA               "3.1.2"

boot      "Unlimited"       NA              NA                    NA      NA     "no"             "3.1.2"

class     "GPL-2 | GPL-3"   NA              NA                    NA      NA     "yes"            "3.1.2"

cluster   "GPL (>= 2)"      NA              NA                    NA      NA     "yes"            "3.1.2"

codetools "GPL"             NA              NA                    NA      NA     "no"             "3.1.2"

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

        C:\Users\hhunter.TRICENTIS\AppData\Local\Temp\RtmpW8YwVX\downloaded_packages

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

        C:\Users\hhunter.TRICENTIS\AppData\Local\Temp\RtmpW8YwVX\downloaded_packages

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)

Introduction to R

R Graphics