2017-04-24 94 views
1

我在R.NET的C#web应用程序中使用R。当我在我的web应用程序中添加下面的代码时,出现以下错误。但是当我在控制台应用程序中运行相同的代码时,它工作正常。我不知道为什么它在web应用程序中不起作用。R.NET找不到函数“cor”

错误消息:

An exception of type 'RDotNet.EvaluationException' occurred in RDotNet.dll but was not handled in user code 

Additional information: Error: could not find function "cor" 

代码:

public double Test() 
    { 
     REngine.SetEnvironmentVariables(); 
     REngine engine = REngine.GetInstance(); 

     if (engine.IsRunning == false) 
     { 
      engine.Initialize(); 
     } 

     NumericVector group1 = engine.CreateNumericVector(new double[] { 30.02, 29.99, 30.11, 29.97, 30.01, 29.99 }); 
     engine.SetSymbol("group1", group1); 
     NumericVector group2 = engine.CreateNumericVector(new double[] { 29.89, 29.93, 29.72, 29.98, 30.02, 29.98 }); 
     engine.SetSymbol("group2", group2); 

     var coefficientValue = engine.Evaluate("cor(group1, group2, method = c('pearson'))"); 
     var coefficientValueNumeric = coefficientValue.AsNumeric(); 
     double pearsonCoefficient = coefficientValueNumeric.ElementAt(0); 
     engine.Dispose(); 

     return pearsonCoefficient; 
    } 
+0

R错误听起来像'stats'包没有得到加载。至于为什么只有当它是一个Web应用程序时才会发生这种情况,也许它与作为不同用户运行的Web应用程序有关。 –

回答