I am new c# developper. I need to run my R scripts within c# program. I find documentation here http://quantlabs.net/academy/very-nice-my-c-program-calls-r-code-through-the-r-net-package-dancing-in-the-streets/ and I tried to adapt it to my project. It usually showing this error :
REngine' does not contain a definition for 'SetDllDirectory'
REngine' does not contain a definition for 'CreateInstance'
I search here , I find suggestions here REngine' does not contain a definition for 'SetDllDirectory', 'RDotNet and I change it but no way.For your information I am working with the latest version of visual studio(2017) and I download the latest R.net package(1.7.0). Please, I need advice and help from whom were working in isssues that include interaction between R and C#.In fact, all my r scripts are just ready to run them in C# program.
My code is:
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();
}
}
}
}