Posted by: joachimvandenbogaert | February 20, 2009

RCOM and C#: SafeArrayTypeMismatchException

R only only accepts safe arrays. In C#, for example the use of jagged arrays is not allowed when passing them to R:

StatConnectorClass RConnector = new StatConnectorClass();
RConnector.Init(
“R”);
double[] input = new double[3][];filling the array and then doing:RConnector.SetSymbol(“input”, input);

will throw an error, even if all the double[] arrays in input have the same length. Instead, you need to use the Array class.

StatConnectorClass RConnector = new StatConnectorClass();
RConnector.Init(
“R”);
Array mySafeArray = Array.CreateInstance(typeof(double), 5, 2);for (int i = 0; i < 5; i ++)
{
     for (int j = 0; j < 2; j++)
    {
        mySafeArray.SetValue(i * j, i, j);
     }
}
RConnector.SetSymbol(
“input”, mySafeArray);

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: