Exception from Hresult: 0X80040013: When Integrating R with C#:

Exception from HRESULT: 0x80040013: when Integrating R with C#:

I have used the COM method to interface to c# some years ago, but I gave up because on each version change there were problems similar to that you mentioned. In addition, the licensing scheme of R(D)COM is a bit obscure to me, and the .NET/COM/R tour has too many corners.

My current choice is Rserve, which is well maintained and has never let me down. I had written my own test bed for c#, but I consider it obsolete because RserveCLI is more complete.

R.NET in theory is a better concept, but for strange reasons it is considered "stable" by the author, which is highly euphemistic because of the many bugs mainly in memory management. Too bad it never took off.

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

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.

Launching an R graph from within C# .NET

To pull a graph from R into .NET, and display it on a WinForms panel:

Sample Image

First, we have to install Statconn, which is the bridge between .NET and R. Its important to install the correct version (it won't work if there is the wrong mix of x32 and x64). The easiest way to ensure this is to install Statconn from within the R console:

# Install Statconn bridge.
# Load the "rcom" package:
install.packages('rcom')
# Load the library 'rcom':
library('rcom')

At this point, it will give an error that you don't have the Statconn library installed. This is easy to fix:

install.packages('statconn')

This will automatically install the correct version of the StatConn bridge, which is a standalone windows installer.

Now that we have installed Statconn, we can open up the sample .NET project in C:\Program Files (x86)\statconn\DCOM\samples\Graphics.NET. This sample .NET project shows how to use R to plot graphics from within a C# WinForms project.

p.s. There is also other sample code for Python, C++, VBS, jscript, etc.

Update

If you cannot get this working, try R.Net, which is probably a better choice because Statconn hasn't been updated in a while, and is quite picky with less than perfect mixtures of '32-bit' / '64-bit' / 'supported R versions'.



Related Topics



Leave a reply



Submit