我想使用RDotNet
將C#連接到R.C#沒有使用RDotNet連接到R
以下代碼是希望R計算兩個數字和C#的總和以獲取結果並將其顯示在命令窗口中。
using System;
using RDotNet;
namespace rcon
{
class Program
{
static void Main(string[] args)
{
string dllPath = @"C:\Program Files\R\R-3.1.0\bin\i386";
REngine.SetDllDirectory(dllPath);
REngine.CreateInstance("RDotNet");
//REngine engine = REngine.GetInstanceFromID("RDotNet");
using (REngine engine = REngine.GetInstanceFromID("RDotNet"))
{
var x = engine.Evaluate("x <- 1 + 2");
Console.WriteLine(x);
}
}
}
}
但是當我嘗試將命令發送到R和取回X的calue我得到了一個錯誤:
"InvalidOperationException was unhandled"
"Operation is not valid due to the current state of the object."
如果我探索對象的「引擎」我看到IsRunning=false
。
這是問題嗎?我怎樣才能解決這個問題,以便能夠連接到R?
'你失蹤在該字符串末尾的「\」'dllPath = @「C:\ Program Files \ R \ R-3.1.0 \ bin \ i386」 – MethodMan 2014-10-03 14:14:44