R.NET找不到功能“cor”

时间:2017-04-24 13:24:08

标签: c# r

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

错误讯息:

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;
    }

2 个答案:

答案 0 :(得分:1)

我找到了这个问题的答案。将c:\ Program Files \ r \ R-3.2.0 \ bin \ i386添加到计算机或用户的PATH环境变量中。

来源:http://jmp75.github.io/rdotnet/tut_asp_dot_net/

答案 1 :(得分:0)

除了Barry的回答:在调整PATH变量并重启服务器时使用正斜杠('/')。这对我有用(最后)