6

我正在尝试R Language使用R.Net 1.5.5 版(从 NuGet 加载)创建一个“Hello World”示例。不幸的是,我见过的在线样本都没有工作。

这就是我所做的:

我的问题:
我看到的所有在线示例都必须使用早期版本,因为我无法REngine为我的生活创建一个实例!事实上,我不断得到:

找不到dll

...但C:\Program Files\Microsoft\MRO\R-3.2.4\bin\x64\r.dll确实存在。

问:如何使用R.Net 1.5.5 版创建 REngine 实例?

我的代码看起来像:

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

1 回答 1

6

我讨厌回答我自己的问题,但在这里......

Microsoft R Open 3.2.4增强的R 发行版安装 x64 文件。因此,在任何 CPU 下运行都会导致失败,因为它将选择 x86(默认情况下)。


Project Properties -> Build 下:在“General”部分

  • 选择x64作为您的Platform Target

在此处输入图像描述

于 2016-05-10T21:59:24.297 回答