Biostatistics with R

Installing R

The R statistical package has separate installers for different operating systems. The major operating systems supported are Linux, Windows and Mac OS (X).

The installation files are available at the the "Comprehensive R Archive Network" (CRAN) kept at many URL locations at different parts of the world. We have to download the R installtion files from any one of them.

A new version of R is released approximately once a year, with "patch releases" occuring on a need basis. In any CRAN location, almost all the past versions are kept. Generally, two successive versions do not differ appreciably in terms of the general statistical and computational algorithms. Thus, most of the commands you will learn in this tutorial will work in both R-3.0.0 and R-3.2.0 versions (may even in R-2.6.0). Only the special extrnal libraries that will not have backward compatibility beyond a point.

The general installation procedure consists of getting into R home page, going to a CRAN site, downloading some version of R software and installing it in the computer. The last step varies with OS. We will now describe procedure for installing R in windows and linux.

Installing R in windows Operating system

1. Go to the R home page at

2. In order to go to the CRAN mirror page, clock on CRAN mirror link under "Download" title. This opens the CRAN mirror page.

3. Choose a CRAN mirror URL. This leads to the CRAN mirror page.

4. Here, click on the link "Download R for Windows".

5. Click on the link "install R for the first time". This opens a page in which latest R version is kept. For example, click on "Download R 3.3.1 for Windows". This downloads an executable like "R-3.3.1-win.exe".

6. Just run this windows installer. This will install R-3.3.1 smoothly. After installation, an R icon will appear on the desktop. Just click on the icon to open R exection window.

Note : There are two versions of the R executable in R-3.3.1\bin\i386 (32-bit) and R-3.3.1\bin\x64 (64-bit). By default only the first is installed on 32-bit versions of Windows, and both on 64-bit version of windows OS.

Installing R in Linux Operating system

while the installer for windows is almost self contained, installtion of R in linux requires many pre-existing software in the linux OS. In order to check this, a configuration file has to be run before compilation. This file checks whether the required software (like for example, fortran, C, C++, Python compilers, X11 windows system etc) are already present in the systems with which the R files can be compiled and linked. If any required file is missing, this configure script will report it and we have to install the software before configuring again. The compiler will compile only after proper configuration.

Following are the steps for installation of R in linux systems:

1. Go to the R home page at

2. In order to go to the CRAN mirror page, clock on CRAN mirror link. This opens the CRAN mirror page.

3. Choose a CRAN mirror URL. This leads to the CRAN mirror page.

4. Here, click on the link "Download R for Linux".

5. In this page, there are many options. We will consider two of them.
If we need to install latest release, click on the release name link like "R-3.3.1.tar.gz". A window appears with facility to download and save this file.
If we want to install slightly older version, click on the link "Source code of older versions of R is available here". Click on this, and navigate to stable but new versions like "R-3.2.5.tar.gz". On click, you can download and save this file.
At the end of the exercise, we get a file like "R-3.2.5.tar.gz" which is a tar zipped directory of whole installation.

6. Create an installation directory :
Now we need to create a directory where R will be installed.

As an example, let /home/user be the R installtion directory decided by us. Do the following:

Copy the file "R-3.2.5.tar.gz" in to /home/user directory. From home directory,

cd /home/user
tar -xvzf R-3.2.5.tar.gz

The above command unpacks the tar zip file, and you have new the directory /home/user/R-3.2.5/ created. All the R install files are here. The configure script is also here. We have to go inside this directory to configure and compile

7. Run configure script:

cd /home/user/R-3.2.5

This script runs and reports the availability of verious software packages required. If any package or packages are no there, it reports. Install them and again run the configure script. If everything is fine, it will run completely and come out.

8. Compilation : Now we are ready for compilation. As with the general linux installations, a make script is provided for this in the installation directory. In order to run the make script, in give the following one word command from inside /home/user/R-3.2.5/ directory:,


The compilation process begins and take many minutes. If compilation errors appear due to some inadequacy, contact systems administrator or someone to fix it by looking at the message.

9. Installtion : Once the compilation is done, we have to install the appropriate files in to basic directories. We need system password for this. This is done by the command,

sudo make install

You are now asked to provide systems password by sudo. Once it is provided, installtion is done by copying proper files to directories like "/user/lib" etc.

10. The R installtion is ready!. Just go to any directory and type,


to start the R prompt.

Installing multiple versions of R in the same machine

We can install multiple versions of R in the same machine. Sometimes multiple versions are required because of the fact that some external libraries will work only upto certain backward versions. We will be forced to install the older versions for these libraries to work.

In the R installation for linux described above, steps 1 to 8 prepare a compiled version of R with executables. Step 9 actually installs this by copying the R executables to files like "/usr/lib", "/usr/local/lib", "/user/bin" etc.

After installing a new version (eg) R-3.2.0, We can start with another R version file like (eg) "R-3.2.9.tar.gz". We can proceed upto step 8 to compile and create executables. After this, do not proceed with installtion step 9 . If you do so, this will overwrite the previous executables in directories like "/user/bin" etc. Just keep them.

In order to run this new version, just navigate in to R installtion directory to find the R executable and run it from there. This executable called "R" is generally found inside "bin" directory inside the installtion directory.

This way, we have one new version as default, and many other old installtions that can be run when need arises. When we give the command "R" from inside any directory, the default version should start since its executables are kept at "/usr/bin" or "/user/local/bin" as the case may be.

For a detailed and best installtion procedure, visit this installtion and administration page of R-CRAN project.