2/13/2017

Intro to Visual Studio 2015 R Project

Last Friday I attended a team meeting where the presenter spoke on R for Microsoft.  I had seen a similar talk a few months ago during the same team meeting.  However, I didn't realize you can build R projects in Visual Studio.

So to get started, download the R framework for Visual Studio 2015 here.

Run the package, then open Visual Studio 2015 IDE, click new project, you'll a new entry for "R":


Create the project, you see the Solution was created:


In the R Interactive window, you can do Help by entering ? and then the question:



The Help window display information on Array:



Attempted to create a Vector, which is similar to an Array, similar to a Collection back in our Visual Basic days, unbound in that it has no predefined max limits:


Defined the variable "x" equal to a Vector "c" with values 1,2,3,45.  Then enter.  To read back the contents of Vector x, simply type x then enter.

Calculations can be performed using our stored Vector x, here we declare variable "y" equal to Vector x & Vector x.  By doing so, it knows the number of values are the same, and multiplies x.1 * x.1 or 1 * 1.  Then x.2 * x.2 = 4.  x.3 * x.3 = 9 and so on:


We can display the length of our Vectors with the length() command:


To List our variables type ls():


To remove our variables type rm(x,y):


Next, we can declare a Matrix, what is a Matrix, ? matrix


And to assign a new variable x to a Matrix, 2 columns and 2 rows with value 1,2,3,4;



Square root:


And finally, from the sample code from the Stanford Statistical Learning class I'm attending:


Next, we can plot to the screen, create 10 random x and 10 random y:


Results:


Add labels "p" for plot, "l" for lines, "b" for both:


And that sums up our Intro to Visual Studio 2015 R Project.


Thanks for reading~!