Integrating R to DotNet framework: creating a web application that reads an external R file and displays the result

1. Follow the intstructions in the rdotnet webpage for more knowledge: http://jmp75.github.io/rdotnet/
2. Include the header file ‘using RDotNet;’ in your controller to write r functions.
3. The following is an example r.net function that I wrote, which calculates the sum of 2 user defined inputs using an external r code sum.r and displays the result:
public JsonResult CalcR(int Text1, int Text2)
{
REngine.SetEnvironmentVariables();
REngine engine = REngine.GetInstance();

var v = engine.CreateInteger(Text1);
var u = engine.CreateInteger(Text2);

engine.SetSymbol(“u”, u);
engine.SetSymbol(“v”, v);

engine.Evaluate(“setwd(\”D:/Users/h224086/Desktop\”)”); //give the file path
engine.Evaluate(“file<-dget(\"add.r\")");
engine.Evaluate("exec<-file(u,v)");

var sum = engine.Evaluate("exec").AsInteger();
engine.SetSymbol("sum", sum);

return Json(sum, JsonRequestBehavior.AllowGet);
}
(I have used jsonResult as return type since I have used ajax calls in the web page. If you are making a normal web application, you can use your preferred return type like action result etc.)
1. Here, Text1 and Text2 are the user inputs.
2. The following commands invokes the r engine and enables to run the r code: REngine.SetEnvironmentVariables();
REngine engine = REngine.GetInstance();

3. These commands are for initializing the user defined values in the R.net environment ie, the REngine. If we don’t do this, we will not be able to pass the values to the external R code.
var v = engine.CreateInteger(Text1);
var u = engine.CreateInteger(Text2);

engine.SetSymbol("u", u);
engine.SetSymbol("v", v);

4. These commands are for reading the external r code into the REngine:
engine.Evaluate("setwd(\"D:/Users/h224086/Desktop\")"); //file path
engine.Evaluate("file<-dget(\"add.r\")"); //code name

5. Now it’s time to pass the user inputs into the code and execute it, using this command:
engine.Evaluate("exec<-file(u,v)");

6. Now, we need to display the sum in the webpage. For this, we need to return the result. Store the result into a new variable sum and return it using the following command:
var sum = engine.Evaluate("exec").AsInteger();
engine.SetSymbol("sum", sum);
7. Now, return the result, which will be displayed in the webpage:
return Json(sum, JsonRequestBehavior.AllowGet);

I hope you are familiar with the ASP.NET web development. The front end development part is same as any simple asp.net app development. If you still have any doubts, please feel free to contact me.

These are a few screen shots of the application developed by me:

1. Sum1

2. sum2

Thank you.

INTRODUCTION TO ANDROID PLATFORM

new-prof
This article will give you a basic idea about the functioning of any android application

Android is one of  the most popular open-source mobile platforms in the world currently developed by Google. It is a software stack created mainly to support touch screen mobile devices such as phones, tablets etc.  It is a Linux based operating system which offers a unified approach to application development for mobile devices which means developers need only develop for Android, and their applications should be able to run on different devices powered by Android.

ARCHITECTURE

android-stack1

Android software stack is organized into several layers:

  •   Linux kernel : bottom layer, provide core services
  •   System library and runtime system:
  •   Application framework: support applications
  •   Application: Direct interaction with the user eg: phone, contact etc.

Linux kernel:

Provides generic operating system services like:

  • Permissions and security: Resources with proper authorizations can access it.
  • Memory and process management: Multiple applications can use same memory or process without interfering with each other.
  • File and network I/O
  • Device drivers: to communicate with hardware devices like cameras, radios, Wifi etc.

It also has android-specific components like power management, memory management and memory sharing. It enables inter-process communication using binders.

System libraries:

Also called native libraries and are written in C and C++. It handles performance-sensitive activities like browsing a web page, in-memory database storage, memory allocation, calculations  etc. For example, Surface manager helps in displaying the data and media framework for audio/video playback.

Android Runtime:

supports writing and running applications. It comprises of

core Java libraries : basic Java classes for file I/O etc.,  XML files for layout, android packages, org* for web applications, manifest files,unit testing files etc.

Dalvik virtual machine: It is the software that executes android applications. This is used for running in the resource-constrained environment since mobile devices have lesser memory, power etc.

Application framework:

It is a reusable software common in all mobile applications that provides it with specific services. It includes:

  • Activity manager: Co-ordinates and supports navigation from one activity to another.
  • Window manager: Basically, android has 3 types of windows: the main window, the sub-window for dialog boxes etc. and the notification bar in the top. Window manager helps in the managing these windows.default-android-photo-gallery
  • Content provider: enables data sharing among different applications. Eg. whatsapp uses the contact details stored in contacts.
  • Resource manager: Manages non-compiled resources like strings, layouts and graphics. It is because of this framework that android is available in multiple languages. All these texts strings are stored as resources(Items stored in ‘res’ file).
  • Telephone manager: establishing a phone call.
  • View system:Provides user-interface elements like buttons, icons and text entries.
  • Package manager: It maintains a database on the applications installed.
  • Location manager:Functioning of GPS system/Google maps to track down a location.
  • Notification manager: Always in the wait for a notification to occur. Any notification produced by any application is displayed by this.

Applications:

Top-most layer that is visible to the users. Some of the basic applications include Contacts, Phone, Home etc. The special feature of android is that you can substitute these standard applications with any better applications.

Hope you found this interesting and informative. Now you have a better idea about the functioning of android in a hand-held system!

 

Adding Colours To My Campus Life:Univ-Fest!!!

I was filled with immense joy when i came to know that i was selected for the south-zone inter-university fest for the theatre events. Theatre is my passion from school days. I was over-joyed by the fact that I have got an oppurtunity to perform and explore my acting skills…. We were a whole bunch of fresh-faces, all aspiring and with budding talent. We practiced very hard, for months with the only motto of winning, which was not an easy task.

Inaugration
Inauguration of the event

The university fest was hosted this time by the Tumkur University, Bangalore from 8th – 12 December 2014. Our entire team consisted of almost 40 students from different branches and different ages for many interesting events. Our journey started on 7th december morning, when we left Amritapuri for the univ-fest. The train journey transformed a few bunch of unknowns into inseperable buddies. We all  had a blast in the train and hard-core fun.

Lying in the borders of bangalore, Tumkur is a very beautiful town. I liked the place in the very first glance, even though it was midnight! The highlight of the journey was that the accomodation for the female contestants and staffs was arranged in the ‘College Boys Hostel ‘, which was vacated for the time-being. Thus my long-time wish of entering a boys hostel was also fulfilled!

images

Our events were on 11th dec, so we rehearsed during the other days day and night. Our break-times were spent joyfully by exploring the vast campus and near-by places, eating and watching other performances.

image
the greeny palak roti

The food was exceptionally delicious, with a huge variety of items… many of which i was seenig for the first time. I will never forget the nasty-looking but yummy green-chappathi(which later on i came to know was palak roti) that we had one day.

A tension occured between all this when cold climate of Tumkur affected my health. I caught a nasty cold and completely  lost my voice. Everyone was panic-stricken, because I was unable to say my dialogues well. But due to god’s grace and proper medication, I was able to regain a part of my voice.

szoneThen came the day of our performance.We were all tensed because we were competing with South India’s best universities, which numbered more than 50. Our first event was skit and then mime. We performed very well. But a lot of technical issues were there like the improper functioning of the sound systems which over-shadowed our performance. But the audience enjoyed our performance and we got a very loud applause. We returned on 11th night, with a contented heart and a heart full of sweet memories.

Later on… when the results were announced, we had 4th for skit. But we were not depressed, we were happy because we have learnt that winning is not always important in life…………