C# - R interface
Ok, I solved it finally.
The problem is that R (D)Com doesn't work with current version of R. I installed 2.11.1 and it worked out of box.
Thanks a lot.
Using R function in C#
You'd need to install R.Net library to run R in .NET Framework.
is there a way to call R functions from C# and retrieve the result in C#
Given there is a COM interface to R, you can use C#'s COM interop to control it.
See this article for more details: http://www.codeproject.com/KB/cs/RtoCSharp.aspx
Using R(D)COM for integrating R with C#
Oh god I remember this being a huge pain in the arse. Lets see if I can remember... And before I start, I warn you that I just "got this working" and never cared to work out if I could remove parts from the process.
Downloads are available from http://rcom.univie.ac.at/download.html . If I remember correctly, the RandFriends package is all you need, it installs a crapload (just install it all) but is simple. Alternatively, I think if you install the 'rscproxy' package in R you can just download the 'statconnDCOM' and install that. Memory is hazy, but I know one of these methods results in an annoying splash screen everytime you run your C# executable, and one doesn't. Although that could have just been some setting I played with.
Now, I can't remember how you verify that stuff has installed successfully. Pretty sure it comes with examples though. Once that is started, get your C# project open. Reference the following projects,
StatConnectorCommonLib
STATCONNECTORSRVLib
In your code, you will probably want to implement a IStatConnectorCharacterDevice
so you get the R output coming back out in C#. Your code to initialise will then look something like,
private StatConnector _StatConn;
private IStatConnectorCharacterDevice _CharDevice;
private Whatever()
{
// declare
_StatConn = new StatConnectorClass();
_CharDevice = new MyCharDevice();
// init R, wire up char device
_StatConn.Init("R");
_StatConn.SetCharacterOutputDevice(_CharDevice);
}
Then you should be able to just use the functions as needed
_StatConn.EvaluateNoReturn("x <- 3");
var returnObj = _StatConn.Evalute("1 + 1");
Hope that helps.
tl;dr download RAndFriends, do fresh install with that
Related Topics
Remove HTML Tags from String Including &Nbsp in C#
How to Pass Parameters by Reference in Java
How to Get All Classes Within a Namespace
How to Parse Hex Values into a Uint
How to Determine If a Type Implements a Specific Generic Interface Type
Converting Dd/Mm/Yyyy Formatted String to Datetime
Is There Any Benefit of Using an Object Initializer
What Is the Minimum Client Footprint Required to Connect C# to an Oracle Database
Insert Entire Datatable into Database at Once Instead of Row by Row
Webbrowser.Drawtobitmap() or Other Methods
Creating a Zip Archive in Memory Using System.Io.Compression
Why Does Boolean.Tostring Output "True" and Not "True"
Xdocument Containing Namespaces