Installing And Setting Up R Environment On Windows

Introduction and Background

One day in the previous week, I heard my professor say something about “R language” and I said to myself, “What is this R language?”. Of course I had no idea about what that language was but I was a bit curious to know about it and to learn about it. Luckily, I was provided with a few concepts about R language on C# Corner’s R language category and later I Googled stuff to learn more about it. In this post, I am going to walk you through different things that I have learned during my learning time.

In this post, I will walk you through many steps to set up the environment for R programming. I will be covering the basic R environment set up and later I will talk about using Visual Studio as the default IDE for R programming, after all, “Who doesn’t like Visual Studio?!”.

What is R, anyways?

A good introduction to the R language and R environment is given by Mahesh on C# Corner, I would recommend that you read that one, What Is R Language.

R is a programming language, as well as an environment for computation. What sort of computation? Statistical computation is the major field for R. However, many fields are using R language for their purposes, for example, Data Scientists are using R language for many analysis that they have to perform on data sets. Data mining etc. come later in the picture.

I will point out a few of the major fields that R can be used in, later, but first a bit of the intro to R language would be useful.

R logo
                                 Figure 1: R logo

R language was developed in the early 1990s for statistical computation purposes. It started all with small modules, then it gathered and gained much reputation from online communities and it became a very popular environment to use in many fields of computer-related sciences. It was developed using C and FORTRAN as the basic language for interpretation.

R is distributed under GNU license and allows modifications to be made and shared online. R was developed in C and FORTRAN. That is why, you can modify the source code and recompile the binaries to make it suitable for your own needs. You can do that, too!

Why learn R?

As already mentioned R is a programming language and environment for statistical programming and computation. That is why R is a very prominent language to be used in data science projects. Specifically, the R language is used instead of C, Java or even C++ in these cases because the packages in R are already ready to be used and in no time, you get to use the best of the data science in this environment.

A chart for benefits of learning R language
                           Figure 2: A chart for benefits of learning R language

Even if you are not an open source developer, you would still find R language very much helpful. The usage of R ranges from field to field. As already depicted in the diagram above, this project can be used in many ways, in many fields and for many purposes. A few of the basics where, this can be used can be categorized as following:

  1. Working with data science projects.
  2. Building reports for data analysis.
  3. Creating presentations with graphical representations of results.
  4. Adding your own extensions to the projects.
  5. Educational use.

I will write some articles about using R in many ways, for many projects and tasks in computer science, but I would like to leave that all to a later time. Until now, just know that if you are going to analyze large amount of data sets, process data mining and similar projects. Then your best bid would be R language instead of C++ or Java.

Another beauty of R language is that it can be coupled with many other famous programming languages and environments and frameworks. For example, R functions can be called from C, C++, Java, Python and from the .NET environment, easily. You would be using the R language to:

  1. Process the data from CSV or TXT files.
  2. Generate summary reports in the form of graphics or tables.
  3. Use a special type of Markdown format to build the results.
  4. Use multiple formats to extract the data results.

There is much more to learn R for. Many giants such as Google and Facebook are already using R for their computation purposes, because it is open source and can be updated as per needs. It allows educational institutes to teach their students in a much simpler and easy way.

Setting up R environment

First step to perform would be to install the R environment packages on your machine. You can get the binaries for installation packages free of cost, from R website itself. Go to the CRAN network and select your own operating system and download the binaries to be used for installation purposes on your own machine.

I am using Windows operating system, so I used Windows instead. You can download the binaries for your own system. Start the setup and continue to follow the steps that are provided on the UI itself.

R installation setup for Windows
                                    Figure 3: R installation setup for Windows

Later you would be asked to select the location where you want to install the packages. Chose a location, but recommendation is to leave it as it is.

Location selection process
                                             Figure 4: Location selection process

Then the environment would be installed. You can run the environment programs by selecting either of the following icons.


Select the one that suits your architecture, mine was 64 bit so I executed the one for my architecture.

Running the R console
                                                   Figure 5: Running the R console

Just to test that everything is running and set up fine, execute the following test on it.

> 3 + 3
[1] 6

Running a test in R console
                                                      Figure 6: Running a test in R console

This shows the R is set up and we can continue to use it in our projects for our own purposes. Now, you don’t want to work on your projects using this console only. For that, you would require a full-featured Integrated development environment; IDE. In the next steps, I will walk you through many steps to install the IDE for R.

Setting up R using Visual Studio

Visual Studio is, no doubt, the best IDE available for everything. It already supports C, C++, C#, VB.NET, Python and many more languages and frameworks such as web development languages of HTML, CSS and JavaScript.

R language support has also just arrived with the “R Tools for Visual Studio” extension that you can install to get started with using R language in Visual Studio. But for this to run, you need to have Visual Studio 2015 with Update 1, any edition would work from Community to Enterprise.

To set up, you can go to the URL provided above. Download the tools, you can also install the Microsoft R Open manually. Microsoft R Open is what we are going to use from now on. Go to this website for Revolution Analytics, and start setting up MRAN (Microsoft’s distribution of CRAN)

  1. Download Microsoft R Open and install it.
  2. Download MKL Math Library, which is going to enhance the performance of MRAN.

Microsoft R Open installer
                                             Figure 7: Microsoft R Open installer

After that, install the MKL and you’re done!

MKL installer
                                                                     Figure 8: MKL installer

After that, just run the Visual Studio IDE to get started with your first R program. That, I am going to cover in an upcoming post.

Points of Interest

In this post, I have talked about a few of the stages that you can undergo to set up your R environment. Before that, I talked about why and how to use R.

In the later posts, I will write about using R language for your computation that require a lot of data processing. See you in the next posts.

Read more articles on R Programming: