Click here to Skip to main content
15,868,141 members
Articles / DevOps

Installing and setting up R environment on Windows

Rate me:
Please Sign up or sign in to vote.
4.85/5 (5 votes)
19 Mar 2016CPOL7 min read 13.2K   1   2
In this post I am going to walk you through installing and setting up the R environment on your Windows operating system; because Visual Studio is only available 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 around to learn more about it. In this post, I am going to walk you through different things that I have learnt 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-Programming-Language-Logo-785x595
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 that 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.

Untitled-1
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.

Screenshot (2752)
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.

Screenshot (2753)
Figure 4: Location selection process.

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

Screenshot (2754)

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

Screenshot (2755)
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

Screenshot (2756)
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.

Screenshot (2811)
Figure 7: Microsoft R Open installer.

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

Screenshot (2812)
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. Apart from that, I also shared a few of the things required to set up R environment on Windows and to use Visual Studio as the default IDE for programming with R language.

If you want to use R on other platforms, you can use RStudio, which is a free and open source IDE for R programming. 

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. :-)

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Pakistan Pakistan
Afzaal Ahmad Zeeshan is a computer programmer from Rabwah, Pakistan, currently living in The Netherlands, likes .NET Core and Node.js for regular everyday development. Afzaal Ahmad works at Adyen as a Developer Advocate.

He is an expert with Cloud, Mobile, and API development. Afzaal has experience with the Azure platform and likes to build cross-platform libraries/software with .NET Core. Afzaal is an Alibaba Cloud MVP, twice he has been awarded Microsoft MVP status for his community leadership in software development, four times CodeProject MVP status for technical writing and mentoring, and 4 times C# Corner MVP status in the same field.

Comments and Discussions

 
QuestionRcpp + RInside under RStudio include path setup Pin
OriCpp8-Sep-16 20:31
OriCpp8-Sep-16 20:31 
AnswerRe: Rcpp + RInside under RStudio include path setup Pin
Afzaal Ahmad Zeeshan9-Sep-16 9:13
professionalAfzaal Ahmad Zeeshan9-Sep-16 9:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.