Quantcast
Channel: R.NET
Viewing all articles
Browse latest Browse all 1634

Commented Issue: RDotNet.ParseException in engine.Evaluate() [48]

$
0
0
When I try to use this code

```
// Задаем путь к библам R, иначе работать не будет
var oldPath = System.Environment.GetEnvironmentVariable("PATH");
var rPath = System.Environment.Is64BitProcess ? @"C:\Program Files\R\R-3.0.1\bin\x64" : @"C:\Program Files\R\R-3.0.1\bin\i386";
var newPath = System.String.Format("{0}{1}{2}", rPath, System.IO.Path.PathSeparator, oldPath);
System.Environment.SetEnvironmentVariable("PATH", newPath);

var engine = REngine.GetInstanceFromID("RDotNet");

// From v1.5, REngine requires explicit initialization.
// You can set some parameters.
if (engine == null)
{
engine = REngine.CreateInstance("RDotNet");
engine.Initialize();
ctx.LogInfo("Created and Inited");
}

// делаем расчеты разные
var closeLogs = new double[ctx.BarsCount];
closeLogs[0] = 0;
for (var i = 1; i < ctx.BarsCount; i++)
{
closeLogs[i] = Math.Log(sec.ClosePrices[i] / sec.ClosePrices[i - 1]);
}

var closeLogsVector = engine.CreateNumericVector(closeLogs);
engine.SetSymbol("closeLogsVector", closeLogsVector);
var mean = engine.Evaluate("mean(closeLogsVector)").AsNumeric(); <<< -- EXCEPTION!!!!!
var stDev = engine.Evaluate("sd(closeLogsVector)").AsNumeric();
ctx.LogInfo("Среднее == {0}\t StDev == {1}", Math.Exp(mean[0]), Math.Exp(stDev[0]));
```
I get an Exception in the string started from "var mean = ". This script is running from another Application. Sometimes i have no errors. But sometimes i have the error. I dont see any stability in this exception. As you see the Engine is initialized once, and in a later iterations of this script I use "var engine = REngine.GetInstanceFromID("RDotNet");". This is not rare situation. I can get the error every second iteration.
```
18:59:01.90 138 RDotNet.ParseException: Error in the application.
at RDotNet.REngine.Parse(String statement, StringBuilder incompleteStatement) in o:\Projects\external\R.NET\rdotnet_311d1b6b5ef6\R.NET\REngine.cs:line 457
at RDotNet.REngine.<Defer>d__0.MoveNext() in o:\Projects\external\R.NET\rdotnet_311d1b6b5ef6\R.NET\REngine.cs:line 365
at System.Linq.Enumerable.LastOrDefault[TSource](IEnumerable`1 source)
at RDotNet.REngine.Evaluate(String statement) in o:\Projects\external\R.NET\rdotnet_311d1b6b5ef6\R.NET\REngine.cs:line 324
at test.RDotNetTest.Execute(IContext ctx, ISecurity sec) in o:\TsLab\test\test\test\RDotNetTest.cs:line 48
at TSLab.User.Script.Execute(IContext context, ISecurity ТорговляMinusВедомый) in c:\Users\ra81\AppData\Local\TSLab\TSLab12\temp\code77.cs:line 34
```

Here is the RDotNet Code
```
IntPtr pointer = Engine.GetFunction<R_tryEval>("R_tryEval")(handle, environment.DangerousGetHandle(), out errorOccurred);
result = errorOccurred ? null : new SymbolicExpression(Engine, pointer);
```
In first string I have some Error and errorOccurred == true. After that I have the exception RDotNet.ParseException
Comments: Work done on https://rdotnet.codeplex.com/workitem/77 now retrieves the error messages from the R engine for ParseException or EvaluationException. This fix will likely make its way to the next release.

Viewing all articles
Browse latest Browse all 1634

Trending Articles