我是新的c#developdper。我需要在c#程序中运行我的R脚本。我在这里找到文档http://quantlabs.net/academy/very-nice-my-c-program-calls-r-code-through-the-r-net-package-dancing-in-the-streets/,我试着让它适应我的项目。它通常显示此错误:
REngine'不包含' SetDllDirectory'
的定义REngine'不包含' CreateInstance'
的定义
我在这里搜索,我在这里找到建议 REngine' does not contain a definition for 'SetDllDirectory', 'RDotNet我改变它但没有办法。为了您的信息,我正在使用最新版本的visual studio(2017),我下载了最新的R.net软件包(1.7.0)。 请,我需要建议和帮助,其中包括R和C#之间的交互。事实上,我所有的r脚本都准备好在C#程序中运行它们。
我的代码是:
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();
}
}
}
}