Can´t evaluate more than 2 in datagrid selected rows from MySql in R

Jul 23, 2012 at 7:56 PM

I have got the following code. It runs for 2 selected items but for more there occurs:
CallbackOnCollectedDelegate.

private void button1_Click(object sender, RoutedEventArgs e)
{

//StatConnector RConnector = new StatConnector();
//RConnector.Init("R");

REngine.SetDllDirectory(@"C:\Progra

m Files\R\R-2.14.0\bin\i386");
using (REngine engine = REngine.CreateInstance("RDotNet"))

if (dataGrid1.SelectedItems.Count > 0)
{
listBox5.Items.Add(dataGrid1.SelectedItems.Count);
for (int i = 0; i < dataGrid1.SelectedItems.Count; i++)
{

System.Data.DataRowView selectedFile = (System.Data.DataRowView)dataGrid1.SelectedItems[i];
string str = Convert.ToString(selectedFile.Row.ItemArray[3]);
listBox1.Items.Add(str);

foreach (object mu in Symboldaten(Convert.ToString(selectedFile.Row.ItemArray[3])))
{
listBox3.Items.Add((double)mu);
}
double[] s = Symboldaten(str);
NumericVector eins = engine.CreateNumericVector(s);



{


switch (i)
{
case 0:
engine.SetSymbol("A", eins);
eins = null;
break;
case 1:
engine.SetSymbol("B", eins);
eins = null;
break;
case 2:
engine.SetSymbol("C", eins);
eins = null;
break;
case 3:
engine.SetSymbol("D", eins);
eins = null;
break;
}
}



}

if (dataGrid1.SelectedItems.Count == 2)
{

var x = engine.EagerEvaluate("x1 <- A + B").AsNumeric();
foreach (var mu in x)
{
listBox4.Items.Add(mu);
}

}

else if (dataGrid1.SelectedItems.Count == 3)
{
var x = engine.EagerEvaluate("x1 <- A + B + C").AsNumeric();
foreach (var mu in x)
{
listBox4.Items.Add(mu);
}
}
else
{
var x = engine.EagerEvaluate("x1 <- A + B + C + D").AsNumeric();
foreach (var mu in x)
{
listBox4.Items.Add(mu);
}
}

}

}
}

Thank you so much in advance.

Best regards

Benjamin

Jul 25, 2012 at 2:01 PM

I would advice you to initialize the engine in the Form constructor and not in the button click. Make engine private memeber of Form class and initialize it only once. In your code to check if all the variables are set, exectute engine.EagerEvaluate("D") and so on. What you are trying to do is very simple and it should work.