2016-07-12 32 views
0

我已經通過NuGet程序包管理器安裝了R.NET.Community,並添加了以下代碼(以便開始工作),但在Rengine.SetEnvironmentVariables()一行中出現錯誤;代碼甚至不會前進。在Rdotnet中使用R引擎時出現異常

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using RDotNet; 

namespace WF_CRM_R 
{ 
    public class CrmLogic 
    { 
     public void GetCrmOutput(Dictionary<int, List<double>> crmInput) 
     { 
      REngine.SetEnvironmentVariables(); 
      REngine engine = REngine.GetInstance(); 

      double[,] input = new double[crmInput[0].Count, crmInput.Count]; 

      for (int i = 0; i < crmInput.Values.Count; i++) 
      { 
       for (int j = 0; j < crmInput.Count; j++) 
       { 
        input[i, j] = crmInput[crmInput.Keys.ElementAt(i)].ElementAt(j); 
       } 
      } 
      var rMatrix = engine.CreateNumericMatrix(input); 
      engine.SetSymbol("my.data.matrix.inj", rMatrix); 
      engine.Evaluate("source('D:/R/Learning R/CRM_TestData_R_Ver5.R')"); 
      var output = engine.GetSymbol("my.data.matrix.inj").AsNumeric(); 
     } 
    } 
} 

錯誤截圖是在這裏。 enter image description here

這是一個簡單的測試Rdotnet,我無法弄清楚什麼是錯的!

回答

1

我快速潛入從R.NET的文件,發現如下:

SetEnvironmentVariables,在Windows上,着眼於通過R安裝程序設置的註冊表設置 。

因此,從這裏我收集到,你需要先安裝R,然後才能使用R.NET。我的猜測是R本身沒有安裝(正確)。

+0

謝謝!我再次檢查。卸載R並通過不同的鏡像重新安裝。有效。 – Modi

相關問題