APPENDIX A

image

Add-On Packages

Over five thousand add-on packages are available for R, which serve a wide variety of purposes. An add-on package contains additional functions and sometimes objects such as example datasets. This appendix explains how to find a package that serves your purpose and install it.

Viewing a List of Available Add-on Packages

To view a list of available add-on packages, follow these instructions:

  1. Go to the R project website at www.r-project.org
  2. Follow the link to CRAN (on the left-hand side)
  3. You will be taken to a list of sites that host the R installation files (mirror sites), as shown in Figure A-1. Select a site close to your location

    9781484201404_Fig12-01.jpg

    Figure A-1. List of mirror sites

  4. Select Packages from the menu on the left-hand side
  5. Select Table of available packages, sorted by name

A list of packages with descriptions of their purpose is displayed, as shown in Figure A-2. You can use the browser tools to search the list, usually by entering Ctrl+F or Cmd+F.

9781484201404_Fig12-02.jpg

Figure A-2. List of available package sorted by name

On selecting a suitable package, you will see a package information page, as shown in Figure A-3. Here you will find a description of what the package does and a reference manual is available in pdf format. You will notice that the package is available to download, but you do not need to do this as it is simpler to install the package from within the R environment.

9781484201404_Fig12-03.jpg

Figure A-3. Package information page for the lme4 package

Installing and Loading Add-On Packages

To use an add-on package, you must first install it, which only needs to be done once. There are a number of packages that are included with the R base installation (such as the foreign package that we used in Chapter 2), which do not need to be installed.

Once a package is installed, it must be loaded before you can use the functions within. The functions will be available for the remainder of the session, so you will need to load the package during each session that you intend to use it.

You can install and load packages from within the R environment, which is explained separately for Windows, Mac, and Linux users.

Windows Users

To install a package:

  1. Select Install Package(s) from the Package menu
  2. The first time you install a package, you will be prompted to select a mirror site, as shown in Figure A-4. Select a site close to your location

    9781484201404_Fig12-04.jpg

    Figure A-4. Selecting a mirror site (Windows)

  3. When prompted, selected the required package from the list, as shown in Figure A-5

9781484201404_Fig12-05.jpg

Figure A-5. Selecting a package to install (Windows)

To load a package:

  1. Select Load Package from the Packages menu
  2. When prompted, select the required package from the list

Mac Users

To install a package:

  1. Select R Package Installer from the Packages & Data menu
  2. When the R Package Installer appears, press Get List
  3. A list of packages is displayed. Select the required package from the list, then select the Install Dependencies tick box and press Install Selected, as shown in Figure A-6

    9781484201404_Fig12-06.jpg

    Figure A-6. Selecting a package to install (Mac)

  4. Close the window

To load a package:

  1. Select R Package Manager from the Packages & Data menu.

    image Note  There is an issue in R version 3.1.0 for Mac which means that you may not be able to open the Package Manager. If you have this problem, you can download a patched version from http://r.research.att.com/. This should be resolved for versions 3.1.1 onwards.

  2. Select the Status box next to the required package so that the status changes to Loaded, as shown in Figure A-7.

    9781484201404_Fig12-07.jpg

    Figure A-7. Loading a package (Mac)

Linux Users

To install a package:

  1. Enter the command:
    > download.packages(packagename, "/home/Username/folder").

    The file path gives the location in which to save the package

  2. When prompted, select a mirror site close to your location

    To load a package, enter the command:

    > install.packages("packagename")
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.37.254