我的代码

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using RDotNet;
using RDotNet.Devices;
using RDotNet.Internals;
using Microsoft.Win32;

namespace Con_R
{


    class Program
    {
        static void Main(string[] args)
        {
            string rhome = System.Environment.GetEnvironmentVariable("R_HOME");
            if (string.IsNullOrEmpty(rhome))
                rhome = @"C:\Program Files\R\R-3.3.1";

            System.Environment.SetEnvironmentVariable("R_HOME", rhome);
            System.Environment.SetEnvironmentVariable("PATH", System.Environment.GetEnvironmentVariable("PATH") + ";" + rhome + @"binx64");

            // Set the folder in which R.dll locates.
            //REngine.SetDllDirectory(@"C:Program FilesRR-2.12.0bini386″);
            REngine.SetDllDirectory(@"C:\Program Files\R\R-3.3.1\bin\x64");

            // REngine e = REngine.CreateInstance("test", new[] { "" });
            using (REngine engine = REngine.CreateInstance("RDotNet", new[] { "-q" }))  // quiet mode
            {

                foreach (string path in engine.EagerEvaluate(".libPaths()").AsCharacter())
                {
                    Console.WriteLine(path);
                }
                engine.Evaluate(".libPaths(C:\\Program Files\\R\\R-3.3.1\\library)");
                engine.Evaluate("source(D:\\R\\Script\\load_forecast_grid.r)");

                Console.ReadLine();
            }
        }
    }
}
得到以下错误 Error 1 'RDotNet.REngine' does not contain a definition for 'SetDllDirectory' C:\Users\Shrinith_Sanil\Documents\Visual Studio 2013\Projects\Con_R\Con_R\Program.cs 161 21 Con_R Error 2 'RDotNet.REngine' does not contain a definition for 'CreateInstance' C:\Users\Shrinith_Sanil\Documents\Visual Studio 2013\Projects\Con_R\Con_R\Program.cs 164 45 Con_R添加了 Error 3 'RDotNet.REngine' does not contain a definition for 'EagerEvaluate' and no extension method 'EagerEvaluate' accepting a first argument of type 'RDotNet.REngine' could be found (are you missing a using directive or an assembly reference?) C:\Users\Shrinith_Sanil\Documents\Visual Studio 2013\Projects\Con_R\Con_R\Program.cs 167 48 Con_R

最佳答案

只需使用 Evaluate 而不是 EagerEvaluate,因为它在当前版本的 RDotNet 上不可用。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using RDotNet;
using Microsoft.Win32;

namespace Con_R
{
    class Program
    {
        static void Main(string[] args)
        {
            string rhome = System.Environment.GetEnvironmentVariable("R_HOME");
            if (string.IsNullOrEmpty(rhome))
                rhome = @"C:\Program Files\R\R-3.3.1";

            System.Environment.SetEnvironmentVariable("R_HOME", rhome);
            System.Environment.SetEnvironmentVariable("PATH", System.Environment.GetEnvironmentVariable("PATH") + ";" + rhome + @"binx64");



            // Set the folder in which R.dll locates.
            //REngine.SetDllDirectory(@"C:Program FilesRR-2.12.0bini386″);
            REngine.SetDllDirectory(@"C:\Program Files\R\R-3.3.1\bin\x64");

            // REngine e = REngine.CreateInstance("test", new[] { "" });
            using (REngine engine = REngine.CreateInstance("RDotNet",  "-q" ))  // quiet mode
            {


                foreach (string path in engine.Evaluate(".libPaths()").AsCharacter())
                {
                    Console.WriteLine(path);
                }
                engine.Evaluate(".libPaths(C:\\Program Files\\R\\R-3.3.1\\library)");
                engine.Evaluate("source(D:\\R\\Script\\load_forecast_grid.r)");

                Console.ReadLine();
            }
        }
    }
}

关于c# - REngine' 不包含 'SetDllDirectory' 的定义,'RDotNet,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38525902/

10-12 20:58