Recently, I Developed an Experiment Application with VB.net(in Windows platform), When the application collected the data,I want to use R to Analysis the data, But I don't know how to Communicate with R (In other word, I want to send R script to R in my own application). I will appreciate if anyone could give me some suggetions or some reference documents. Thank you very much!
问题:
回答1:
I'd suggest you try R.NET. The blurb says:
R.NET enables .NET Framework to collaborate with R statistical computing. R.NET requires .NET Framework 4 and native DLLs installed with R environment. You need no other extra installations. Enjoy statistics and programming in your special language with R.
It is an open source binding that seems a bit simpler than the statconn tools, since it doesn't go through DCOM. LGPL licensed, so free for commercial use too. And you can combine with Excel-DNA to expose R via .NET to Excel - some discussion here: http://www.r-bloggers.com/yet-another-way-to-use-r-in-excel-for-net-programmer/.
回答2:
An alternative to both statconn, and R.Net is to use the mt4r dll and simply drop the cMT4R C# class into your project and start using R. I have used statconn and still often do for speed of passing data. I never figured out R.Net.
But if you are trying to get up and running with the simplest possible installation, take a look at the following link that describes the interface and the installation for MT4R. After including the C# class in your project, you simply have to update the class with your computer's R path and the DLL will do the heavy lifting. The class interface is intuitive and simple to use.
https://sites.google.com/site/marketformula/vb6-to-c/vb6-to-c-downloads/calling-r-from-csharp-dotnet
There is also a VB6 class available (linked in the post above) if anyone is still kicking around on VB6 or uses VBA and wants a way to get up and running with R quickly with an easy installation.
A simple demo application is included that shows how to send and receive data from C# to R.
回答3:
For this purpose user StatConn DCOM library instead of R.NET. In my own experience it is much more stable than the .NET library.
In order to do this you need to install R, add extensions rcom and rsproxy from any CRAN repository and install StatConn DCOM. Once these are installed you may check to see if your R connection is working via those sample programs come with the DCOM package.
If these are working you may add all statconn references to your .NET project via Visual Studio.
Good luck