Installation

In this section, we will see how you can obtain and install R on your computer. There are two main ways to install R; by downloading the binary distribution or by compiling the software from a source. Both methods will be described in the following sections.

Step 1 – obtaining and installing R

R can be obtained by downloading it from the CRAN website (http://www.r-project.org/). The Comprehensive R Archive Network (CRAN) is a network of FTP and web servers around the world that store identical, up-to-date versions of code and documentation for R. The CRAN is directly accessible from the R website, and on such a website it is also possible to find information about R, some technical manuals, the R journal, and details about the packages developed for R and stored on the CRAN repositories. You can find detailed information of such websites in the section People and places you should get to know.

Binary distribution

Binary distribution will very likely be the one for you. It is a compiled version of R that can be downloaded and installed directly on your system.

For a Windows system, this version comes as a unique .exe (downloadable from the CRAN website) file, which can be easily installed by double-clicking on it and following the few steps of the installation. Once the process is completed, you can start R via the icon on your desktop or via its location in the list of programs available on the system.

For a Mac OS X system, R is also available as a unique installation file, .pkg, which can be downloaded and installed on the system.

For a Linux system, there are several versions of the installation file. In the download section, it is necessary to select the appropriate version of R depending on the Linux distribution. Installation files are available in two main formats, .rpm for Fedora, Suse, or Mandriva and .deb for Ubuntu, Debian, and Linux Mint.

Installation from source

Installation of R from source code is possible on all supported platforms, although it is not very easy on Windows since the installation tools are not part of the system. Detailed information on the process and the tools required are available on the CRAN website. On Unix-like systems, the process is much simpler; the installation must be performed following the usual steps:

./configure
make
make install

Such procedures work assuming that the relevant compilers and support libraries are available and correctly installed. A more detailed description of the installation procedure can be found on the CRAN website (http://www.r-project.org/).

Step 2 – R versions

As you will see, there are constantly new versions of R released thanks to the work of the development community. It would be best if you download and install the most recent release; at the time of writing this book, the latest version is the 2.15.2 one. In case you already have R installed on your computer, you can check its version by navigating to Help | About in the cascade menu or by typing R.Version() on the R console. This function can be particularly useful in case you would need to write some code to extract the version number automatically from the system; for example, to verify that the user is not using a version of R older than the one you used to write your code.

Step 3 – news

Once you have R installed on your system, it may be interesting for you to check the differences of the current version from the previous one. If this may be negligible at the beginning, this may become quite important as soon as you become familiar with R and you have defined your way of interacting with the system. Also, this may become important if you would like to check that some code you wrote in the past is still working properly. Usually the changes of each version from the previous one are referred to as "news". You can access the news of the current R version by simply calling the function news() without any argument.

Step 4 – package installation

One of the main reasons why R is a very powerful and advanced environment is the numerous extensions that can be added to the basic environment via extension packages. There are two main methods to install such packages in R. Most of them are available on the CRAN repositories; so in this case the desired package can simply be chosen from the list of available packages by navigating to Packages | Install package(s). Installation of a package from the CRAN may also be launched from the R console. In both cases, the Internet connection needs to be active and for Linux systems you should have root rights. For example, to install the package lattice we can use the following command:

> install.packages("lattice")

If the package is not available on the CRAN, or if you would need to install the package directly from the package file, it can be done on the R GUI in Windows by navigating to Packages | Install Package(s) from local zip files. The extension of the package file may be different depending on the operating system; please check the section Binary Distribution for more details.

Step 5 – using Integrated Development Environment for R

As soon as you become more experienced with R, you may notice that the GUI development environment provided together with R may become quite difficult to use, especially if you have to deal with several scripts at the same time. For this reason, it may become useful for you to start using Integrated Development Environment (IDE). The number of specific IDEs that get integrated with R is still limited, but some of them are quite efficient, well designed, and open source. The three most important IDEs for R are RStudio, Eclipse, and Emacs.

RStudio

RStudio is probably the only development environment developed specifically for R. It is available for all the major platforms (Windows, Linux, and Mac OS X) and it can be run on a local machine such as your computer or even over the Web using RStudio Server. With RStudio Server you can provide a browser-based interface (the RStudio IDE) to a version of R running on a remote Linux server.

For information about where to download this program, please refer to the section People and places you should get to know. It allows you to integrate several useful functionalities that are extremely useful, especially if you use R for some more complex projects. The environment is composed of four different areas:

  • Scripting area: In this area you can open, create, and write your scripts.
  • Console area: This area is the actual R console on which the commands are executed.
  • Workspace/History area: In this area you can find a practical summary of all the objects created in the workspace in which you are working.
  • Visualization area: Here you can easily load packages and open R help files, but even more importantly, you can visualize plots.

Thanks to such an area separation, RStudio allows you to efficiently manage the several components you will have to deal with, such as scripts, commands, plots, and so on.

For more details on how to install and use RStudio, you can refer to the official website of the project, on which you can find useful video tutorials and documentation. Let us take a look at the following screenshot that shows the RStudio on Windows 8:

RStudio

Eclipse

Eclipse is an open source IDE that was originally developed for Java, but was later extended to other applications and programming languages such as C++ and Python as well. Eclipse is structured in such a way that it is particularly useful for the management of complex programming projects, for example, when you have your projects divided in several folders, since Eclipse allows you to keep a grip on all the files simultaneously. One inconvenience of such a development environment is probably its huge size (around 200 MB) and a slightly slow start-up time for the environment.

Eclipse does not support natively the interaction with R; so in order to be able to write your code and execute it directly in the R shell, you need to add StatET to your basic Eclipse installation. StatET is a plugin for the Eclipse IDE and it offers a set of tools for R coding and package building. More detailed information on how to install Eclipse and StatET and how to configure the connections between R and Eclipse can be found on the websites of the relative projects listed in the section People and places you should get to know.

Emacs

Emacs is a customizable text editor that is very popular particularly in the Linux environment. Although this text editor appears with a very simple GUI, it is an extremely powerful environment, particularly thanks to the numerous key shortcuts that allow interacting with the environment in a very efficient manner. Also, if a normal desktop computer IDE such as RStudio is more complete for a better graphical visualization of R results, Emacs may be useful in case you will need to work with R on systems with a poor graphical interface, such as servers. Along with Eclipse, Emacs, by default, does not support the interface with R, so you will need to install on your Emacs an add-on package such as Emacs Speaks Statistics (ESS), which will allow for doing that. ESS is designed to support the editing of scripts and interaction with various statistical analysis programs including R.

..................Content has been hidden....................

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