My code runs just fine with one data set but fails at the same point each time a different data set is run. Two different arrays are created in a loop through a large data set using "engine.CreateNumericVector(arGroup1Intensities)" and "engine.CreateNumericVector(arGroup2Intensities)". The data sets are comprised of 207 and 623 members (doubles), respectively. After 223 iterations, I get an error "attempted to read or write protected memory." After going back and checking, it appears that the first array was created fine (207 members), but was reduced to just 1 member when the second array was created. Any suggestions how to fix this?
The "engine" is an REngine that is created at the top of the loop with "using (REngine engine = REngine.CreateInstance("Test")". The creation and checking of arrays is accomplish within the loop with:
vGroup1 = engine.CreateNumericVector(arGroup1Intensities);
Console.WriteLine(vGroup1.Length);
vGroup2 = engine.CreateNumericVector(arGroup2Intensities);
Console.WriteLine(vGroup2.Length);
engine.SetSymbol("group1", vGroup1);
engine.SetSymbol("group2", vGroup2);
GenericVector testResult = engine.Evaluate("t.test(group1, group2)").AsList();
Comments: If I run exactly the same dataset, calculate the t-statistic separately and then pass this and DOF to the pt function in R, it runs just fine. The issue seems to be related to memory allocation.
The "engine" is an REngine that is created at the top of the loop with "using (REngine engine = REngine.CreateInstance("Test")". The creation and checking of arrays is accomplish within the loop with:
vGroup1 = engine.CreateNumericVector(arGroup1Intensities);
Console.WriteLine(vGroup1.Length);
vGroup2 = engine.CreateNumericVector(arGroup2Intensities);
Console.WriteLine(vGroup2.Length);
engine.SetSymbol("group1", vGroup1);
engine.SetSymbol("group2", vGroup2);
GenericVector testResult = engine.Evaluate("t.test(group1, group2)").AsList();
Comments: If I run exactly the same dataset, calculate the t-statistic separately and then pass this and DOF to the pt function in R, it runs just fine. The issue seems to be related to memory allocation.