Table of Contents
CHAPTER 1: Installing and starting working with R
It is sometimes said that R is an open source analogue of statistics software. Often you will hear that R is a programming language, but many programmers complain a lot about R, bewildered with its quirks. A more correct definition was given by John Cook during his talk on R. R is not a language; it is an environment with a language that contains all the tools for doing statistics coupled with R language. R language itself is a dialect of S language, as many constructs in R came from S while some were added later. In this chapter, we will install R and get a first whiff of it. This chapter includes the following paragraphs:
Does version matter?
Installing R
R user interface
R console
R primer
Does version matter?
R language does not change much over the years. Although releases are frequent, they tend to contain bug fixes rather than major changes in R language. The language is changing as well, but this process goes slowly and in a way that will not inconvenience most users of R. In other words, you can use the latest version of R with little worry about what version was used to write this course.
You should also keep in mind that R language is not fully standardized as some other programming languages are. Therefore, sometimes R may behave in an incomprehensible manner. In this case, you should consult the official documentation of R and if you cannot find the answer, try asking more experienced R users.
Installing R
R is available for all primary desktop computing platforms. Any developer can port R to a new platform since Rs implementation is open source. In addition, R is free software. You can use the binary that comes with this course or, alternatively, get the fresh version from the Internet:
1. Go to the official R website. A link to Download is visible on the site.
2. The download link leads you to a list of mirror sites. The list is arranged by country. You will probably require choosing a site that is geographically located near you, since it is likely to be also close on the Internet and, therefore, providing quicker download.
3. Look for the proper binary for your platform and launch the installer. A few things should be kept in mind depending on the type of system you are utilizing.
Windows
Installing R on Windows is similar to installing other types of software on Windows. This means that it is a very simple process if you have the necessary rights, and it would be difficult if you do not. If R is being installed on your personal computer, this is not a great trouble. Nevertheless, if you are dealing with a corporate environment, you might have some problems. If you are Power User on Windows or an Administrator, installation is plain: the installer should be double-clicked and the on-screen instructions should be followed.
Mac OS X
Both PowerPC and Intel based Mac systems running Mac OS X 10.4.4 (Tiger) and higher use the current version of R. If you are employing an older computer or operating system, older versions can be found on the website and they will show better performance dealing with your system. Three different R installers for Mac OS X are available: a three-way universal binary for Mac OS X 10.5 (Leopard) and higher, a legacy universal binary for Mac OS X 10.4.4 and higher with supplemental tools, and a legacy universal binary for Mac OS X 10.4.4 and higher without supplemental tools . The universal binary of R exists as an installer package; the file is quickly downloaded, and the package is double-clicked for installing the application. A disk image file (similar to most Mac OS X applications) contains the legacy R installers. If the disk image is downloaded, it should be double-clicked to open it in the finder (if there is no automatic opening). The volume should be opened, and the R.mpkg icon should be double-clicked for starting the installer. Sticking to the directions in the installer will allow you to have a working copy of R on your computer.
Linux and UNIX
Before the process is launched, make sure that the systems root password is known to you or make sure that you have sudo privileges on the system. If you do not, you will need help from the system administrator to install R. The simplest method of installing R on a Linux system is via a package management system. These systems automate the installation procedure: they download the R binaries or sources, receive any other software that is required for launching R, and even upgrade quickly to the latest version. For instance, Yum (which stands for Yellow Dog Updater, Modified) can be used to automate the installation on Red Hat or Fedora. Open a terminal window and input the following on an x86 Linux platform:
sudo yum install R
You will enter your password, and if your user has sudo privileges, R has to be installed on your system. Then R can be updated by entering:
sudo yum update R
If a new version is available, yum will now upgrade your R installation to the latest version.
If you are using another UNIX system, you will be able to install R as well: view the documentation for your system to obtain more details about how software should be installed.
R can also be manually downloaded in order to be installed later. There are a lot of precompiled R packages for different flavors of Linux. For example, there are rpm packages for Red Hat Package Manager to be used on Red Hat systems.
Refer to your user documentation for obtaining more information on using package management systems.
R user interface
Lets begin with launching R and looking at Rs graphical user interface on multiple platforms. When R application is installed on Windows or Mac OS X, a command window and some menu bars will become visible. On most Linux systems, R application will simply start working by means of the command line.
Windows
By default, installation of R is located in %ProgramFiles%R (which is commonly equal to C:\Program Files\R ) and R can be accessed via the Start menu. When you launch R in Windows, something like the user interface illustrated in Figure 1-1 will be shown. The R GUI window demonstrates a menu bar, a toolbar, and the R console.
Figure 1-1
Mac OS X
An application named R will be added by the default R installer to your Applications folder and can be launched like any other application on your Mac. When R application is started on Mac OS X systems, something like the screen illustrated in Figure 1-2 will be visible. Similar to the Windows system, a menu bar, a toolbar with common functions, and an R console window are visible.
Figure 1-2
On a Mac OS system, R can be launched from the terminal without utilizing GUI. Doing this requires opening the terminal window that is contained in the Utilities folder inside the Applications folder. Once in the terminal window, just type the command R to start the R environment.
Linux and UNIX
On Linux systems, R can be launched from the command line by entering:
R
Pay attention that it is a capital R: filenames on Linux are considered to be case sensitive. An interactive R session will be started by the command line itself, unlike the default applications for Mac OS and Windows. It is possible to start R in an application window which resembles the user interface on other platforms. Doing this requires applying the following command: