We begin with a discussion of obtaining and installing R and provide an overview of its uses and general information on getting started. In Section , we provide some general recommendations for reading this book and how to use it if you are an instructor, and finally, in the last section, we summarise the R functions introduced in this chapter.
1.1 What Is R?
It is a simple question, but not so easily answered. In its broadest definition, R is a computer language that allows the user to program algorithms and use tools that have been programmed by others. This vague description applies to many computing languages. It may be more helpful to say what R can do. During our R courses, we tell the students, R can do anything you can imagine, and this is hardly an overstatement. With R you can write functions, do calculations, apply most available statistical techniques, create simple or complicated graphs, and even write your own library functions. A large user group supports it. Many research institutes, companies, and universities have migrated to R. In the past five years, many books have been published containing references to R and calculations using R functions. A nontrivial point is that R is available free of charge.
Then why isnt everyone using it? This is an easier question to answer. R has a steep learning curve! Its use requires programming, and, although various graphical user interfaces exist, none are comprehensive enough to completely avoid programming. However, once you have mastered Rs basic steps, you are unlikely to use any other similar software package.
The programming used in R is similar across methods. Therefore, once you have learned to apply, for example, linear regression, modifying the code so that it does generalised linear modelling, or generalised additive modelling, requires only the modification of a few options or small changes in the formula. In addition, R has excellent statistical facilities. Nearly everything you may need in terms of statistics has already been programmed and made available in R (either as part of the main package or as a user-contributed package).
There are many books that discuss R in conjunction with statistics (Dalgaard, 2002; Crawley, 2002, 2005; Venables and Ripley, 2002; among others. See Section for a comprehensive list of R books). This book is not one of them. Learning R and statistics simultaneously means a double learning curve. Based on our experience, that is something for which not many people are prepared. On those occasions that we have taught R and statistics together, we found the majority of students to be more concerned with successfully running the R code than with the statistical aspects of their project. Therefore, this book provides basic instruction in R, and does not deal with statistics. However, if you wish to learn both R and statistics, this book provides a basic knowledge of R that will aid in mastering the statistical tools available in the program.
1.2 Downloading and Installing R
We now discuss acquiring and installing R. If you already have R on your computer, you can skip this section.
The starting point is the R website at ) shows several nice graphs as an appetiser, but the important feature is the CRAN link under Download . This cryptic notation stands for Comprehensive R Archive Network, and it allows selection of a regional computer network from which you can download R. There is a great deal of other relevant material on this site, but, for the moment, we only discuss how to obtain the R installation file and save it on your computer.
Fig. 1.1
The R website homepage
If you click on the CRAN link, you will be shown a list of network servers all over the planet. Our nearest server is in Bristol, England. Selecting the Bristol server (or any of the others) gives the webpage shown in Fig. ) that allows us to choose between the base installation file and contributed packages. We discuss packages later. For the moment, click on the link labelled base .
Fig. 1.2
The R local server page. Click the Linux, MacOS X, or Windows link to go to the window in Fig.
Fig. 1.3
The webpage that allows a choice of downloading R base or contributed packages
Clicking base produces the window (Fig. ) from which we can download R. Select the setup program R-2.7.1-win32.exe and download it to your computer. Note that the size of this file is 2530 Mb, not something you want to download over a telephone line. Newer versions of R will have a different designation and are likely to be larger.
Fig. 1.4
The window that allows you to download the setup file R-2.7.1-win32.exe . Note that this is the latest version at the time of writing, and you may see a more recent version
To install R, click the downloaded R-2.7.1-win32.exe file. The simplest procedure is to accept all default settings. Note that, depending on the computer settings, there may be issues with system administration privileges, firewalls, VISTA security settings, and so on. These are all computer- or network-specific problems and are not further discussed here. When you have installed R, you will have a blue desktop icon.
To upgrade an installed R program, you need to follow the downloading process described above. It is not a problem to have multiple R versions on your computer; they will be located in the same R directory with different subdirectories and will not influence one another. If you upgrade from an older R version, it is worthwhile to read the changes files. (Some of the information in the changes file may look intimidating, so do not pay much attention to it if you are a novice user.)
1.3 An Initial Impression
We now discuss opening the R program and performing some simple tasks. Startup of R depends upon how it is installed. If you have downloaded it from www.r-project.org and installed it on a standalone computer, R can be started by double-clicking the desktop shortcut icon or by going to Start- > Program- > R . On network computers with a preinstalled version, you may need to ask your system administrator where to find the shortcut to R.
The program will open with the window in Fig.. This is the starting point for all that is to come.