I am trying to make RDotNet work with C # and I am facing problems

I'm on a 64-bit Windows machine. In Visual Studio 2012, it works in a web environment.

I used nuget to install the latest version of R.net (1.5.5), last published on 09/16/2013,

I tried installing Path (both the user and the system) to enable directrory "E: \ Program Files \ R \\\\\\\\\\\\\\\\\\\\\\\\ \\\\ \

I also tried this code according to some suggestions ...

// As per the example var envPath = Environment.GetEnvironmentVariable("PATH"); const string rBinPath = @"E:\Program Files\R\R-3.0.2\bin\x64"; Environment.SetEnvironmentVariable("PATH", envPath + Path.PathSeparator + rBinPath); 

Before calling

 // Create an instance of the engine engine = REngine.CreateInstance("RDotNet"); Initialize(); 

But I get this DllNotFound error .....

 RDotNet.NativeLibrary.UnmanagedDll..ctor(String dllName) +267 RDotNet.REngine..ctor(String id, String dll) +55 RDotNet.REngine.CreateInstance(String id, String dll) +415 

I researched and found that others made suggestions on how to fix this https://rdotnet.codeplex.com/discussions/353957 I read this and tried various things, including the "deprecated" SetDllDirectory (dllDirectory As String), and received a message that it is out of date, and I should not use it.

So I'm a bit of a dead end. Does RDotNet work on 64-bit? I read that the problem may be related to RlaPack.dll, referencing another Dll, I do not have

I also read that you need to set hints about R_Home ... but then others who say that this works in windows and I don't need to set R_home.

So, a small guide from the community, please, for the fact that I can try thanks to anyone who has experience with RDotNet / R in a C # environment

+7
c # r rdotnet
source share
1 answer

This works great for me. Before invoking the R engine, you must configure the R path. For example, you can install it using this function:

 public static void SetupPath(string Rversion = "R-3.0.0" ){ var oldPath = System.Environment.GetEnvironmentVariable("PATH"); var rPath = System.Environment.Is64BitProcess ? string.Format(@"C:\Program Files\R\{0}\bin\x64", Rversion) : string.Format(@"C:\Program Files\R\{0}\bin\i386",Rversion); 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); } 

Then you call it, for example:

  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(); } } 

EDIT is the best method: read the path from the registry:

  RegistryKey registryKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\R-core\R"); string rPath = (string)registryKey.GetValue("InstallPath"); string rVersion = (string)registryKey.GetValue("Current Version"); registryKey.Dispose(); 
+7
source share

All Articles