SEHE Exception使用RDotNet运行R脚本

时间:2016-08-05 13:23:24

标签: c# r r.net

我收到例外'System.Runtime.InteropServices.SEHException' in RDotNet.dll

运行一个简单的R脚本:

n + minWidth

使用c#中的代码:

// Load the R environment
REngine.SetEnvironmentVariables();
REngine engine = REngine.GetInstance();

// Load the input data
CharacterVector charVec = engine.CreateCharacterVector(new List<string> { csvFileName });
engine.SetSymbol("input", charVec);
engine.SetSymbol("n", engine.CreateNumeric(numberOfFanfolds));
engine.SetSymbol("minWidth", engine.CreateNumeric(minWidth));
engine.SetSymbol("minScrap", engine.CreateNumeric(minScrap));
engine.SetSymbol("cardboardStep", engine.CreateNumeric(cardboardStep));

// Run the script
results = await Task.Factory.StartNew(() => engine.Evaluate("source('" + script_file_ + "')"));

当我尝试直接运行代码时,它可以正常工作:

var results = await Task.Factory.StartNew(() => engine.Evaluate("n + minWidth"));

这意味着什么?我能做什么?我是否需要以某种方式格式化R脚本?

1 个答案:

答案 0 :(得分:0)

只需要重新排列文件路径

script_file_ = scriptFile.Replace("\\", "/");