Category Archives: R Fundamentals

Installing and loading add-on packages in R

Over three 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 article explains how you can 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 the instructions below:

  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). Select a site close to your location.
  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. You can use the browser tools to search the list, usually by entering Ctrl+F or Cmd+F.

On selecting a suitable package, a 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.

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, 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. Select a site close to your location.
  3. When prompted, selected the required package from the list.

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. Press ‘Get List’
  3. A list of packages is displayed. Select the required package and press ‘Install Selected’.
  4. Close the window.

To load a package:

  1. Select ‘R Package Manager’ from the ‘Packages & Data’ menu.
  2. Tick the status box next to the required package so that the status changes to ‘loaded’.

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:

  1. Enter the command:
    install.packages("packagename")

Getting started with R

About R

R is a statistical analysis and graphics environment and also a programming language. It is command driven and very similar to the commercially-produced S-Plus® software. R is known for its professional looking graphics, which allow complete customisation.

R is open source software and free to install under the GNU general public license. It is written and maintained by a group of volunteers known as the R core team.

The base software is supplemented by over three thousand add-on packages developed by R users all over the world, many of whom belong to the academic community. These packages cover a broad range of statistical techniques including some of the most recently developed and niche purpose. Anyone can contribute add-on packages, which are checked for quality before they are added to the collection.

At the time of writing, the current version of R is 2.15.

Downloading and installing R

The R software is freely available from the R website. Windows® and Mac® users should follow the instructions below to download the installation file:

    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). Select a site close to your location.
    4. Select your operating system. There are installation files available for the Windows, Mac and Linux® operating systems.
    5. If downloading R for Windows, you will be asked to select from the ‘base’ or ‘contrib’ distributions. Select the ‘base’ distribution.
    6. Follow the link to download the R installation file and save the file to a suitable location on your machine.

To install R for the Windows and Mac OS environments, open the installation file and follow the instructions given by the set-up wizard as you would for any other piece of Windows-based software. You will be given the option of customising the installation, but if you are new to R I recommend that you use the standard installation settings. If you are installing R on a networked computer, you may need to contact your system administrator to obtain permission before performing the installation.

For Linux users, the simplest way to install R is via the package manager. You can find R by searching for r-base-core. Detailed installation instructions are available in the same location as the installation files.

If you have the required technical knowledge then you can also compile the software from the source code. An in-depth guide can be found at:

www.stats.bris.ac.uk/R/doc/manuals/R-admin.pdf


Social Widgets powered by AB-WebLog.com.