rDotNet NullReference使用评估

时间:2018-09-04 18:16:04

标签: vb.net r.net

我正在尝试使用VB代码在Visual Studio中运行rDotNet,但遇到问题,在调用评估函数时,我会立即获得nullreference。

    Try
        REngine.SetEnvironmentVariables()
        Dim engine As REngine = REngine.GetInstance
        Dim group1 As NumericVector = engine.CreateNumericVector({30.02, 29.99, 30.11, 29.97, 30.01, 29.99})
        engine.SetSymbol("group1", group1)

        Dim group2 = engine.Evaluate("group2 <- c(29.89, 29.93, 29.72, 29.98, 30.02, 29.98)").AsNumeric
        Dim testResult As GenericVector = engine.Evaluate("t.test(group1, group2").AsList
        Dim p As Double = testResult("p.value").AsNumeric.First

        Console.WriteLine("Group1: [{0}]", String.Join(", ", group1))
        Console.WriteLine("Group2: [{0}]", String.Join(", ", group2))
        Console.WriteLine("P-value = {0:0.000}", p)
    Catch ex As Exception
        Debug.Print(ex.ToString)
    End Try

问题发生在Dim group2。使用Microsoft的示例代码。例外:

System.NullReferenceException: Object reference not set to an instance of an object.
   at RDotNet.SymbolicExpression..ctor(REngine engine, IntPtr pointer)
   at RDotNet.ExpressionVector.GetValue(Int32 index)
   at RDotNet.ExpressionVector.get_Item(Int32 index)
   at RDotNet.Vector`1.<GetEnumerator>d__0.MoveNext()
   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
   at RDotNet.REngine.Parse(String statement, StringBuilder incompleteStatement)
   at RDotNet.REngine.<Defer>d__0.MoveNext()
   at System.Linq.Enumerable.LastOrDefault[TSource](IEnumerable`1 source)
   at RDotNet.REngine.Evaluate(String statement)
   at TradingOracle.frmTest.frmTest_Load(Object sender, EventArgs e)
Exception thrown: 'System.NullReferenceException' in RDotNet.dll

0 个答案:

没有答案