使用R.Net 1.5.5版创建REngine实例 [英] Creating an instance of the REngine using R.Net version 1.5.5
问题描述
我正在尝试使用 R.Net 1.5.5 (从NuGet加载)在R Language
中创建"Hello World"示例.不幸的是,我见过的所有在线样本都没有工作.
I am trying to create a "Hello World" example in R Language
using R.Net version 1.5.5 (loaded from NuGet). Unfortunately, none of the online samples that I have seen work.
这就是我要做的:
- 已安装 Microsoft R Open 3.2.4,增强的R发行版
-
已安装用于Visual Studio的R工具( R版本3.2.4(2016-03-16))
- Installed Microsoft R Open 3.2.4, the enhanced R distribution
Installed R Tools for Visual Studio (R version 3.2.4 (2016-03-16))
创建了一个R项目&测试了一个简单的脚本
Created an R Project & tested a simple script
我的问题:
我看到的所有在线示例都必须使用早期版本,因为我无法为我的生命创建REngine
的实例!实际上,我不断得到:
MY PROBLEM:
All of the online examples I have seen must be using an earlier version because I cannot create an instance of the REngine
for the LIFE of me! In fact, I keep getting:
找不到Dll
Dll was not found
...但C:\Program Files\Microsoft\MRO\R-3.2.4\bin\x64\r.dll
确实存在.
问::如何使用 R.Net 1.5.5版创建REngine的实例?
Q: How do I create an instance of the REngine using R.Net version 1.5.5?
我的代码看起来像:
class Program
{
#region <Methods>
static void Main(string[] args)
{
SetupPath(); // current process, soon to be deprecated
using (REngine engine = REngine.CreateInstance("RDotNet"))
{
engine.Initialize(); // required since v1.5
CharacterVector charVec = engine.CreateCharacterVector(new[] {"Hello, R world!, .NET speaking" });
engine.SetSymbol("greetings", charVec);
engine.Evaluate("str(greetings)"); // print out in the console
string[] a = engine.Evaluate("'Hi there .NET, from the R engine'").AsCharacter().ToArray();
Console.WriteLine("R answered: '{0}'", a[0]);
}
Console.WriteLine("Press any key to exit the program");
Console.ReadKey();
}
public static void SetupPath()
{
var oldPath = System.Environment.GetEnvironmentVariable("PATH");
var rPath = @"C:\Program Files\Microsoft\MRO\R-3.2.4\bin\x64";
if (!Directory.Exists(rPath))
throw new DirectoryNotFoundException(string.Format(" R.dll not found in : {0}", rPath));
var newPath = string.Format("{0}{1}{2}", rPath, System.IO.Path.PathSeparator, oldPath);
System.Environment.SetEnvironmentVariable("PATH", newPath);
}
#endregion
}
推荐答案
我不想回答我自己的问题,但这是...
I hate to answer my own question, but here it is...
Microsoft R Open 3.2.4 增强的R发行版会安装x64文件.因此,在任何CPU上运行都会导致失败,因为它将选择x86(默认情况下).
The Microsoft R Open 3.2.4 enhanced R distribution installs x64 files. As such, running under ANY CPU will cause a failure because it will choose x86 (by default).
下
项目属性->构建:在常规"部分
Under
Project Properties -> Build: in the "General" section
- 选择 x64 作为您的
Platform Target
- Choose x64 as your
Platform Target
这篇关于使用R.Net 1.5.5版创建REngine实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!