Hi, I'm new to R but really would love to use it in my C# programs via RDotNet. I've added R.net via Manage NuGet Packages in VS2013 (RDotNet runtime Version v4.0.30319).
Within Windows 7 I'm running R-3.2.2 and both 32bit and 64bit reside within my C:\Program Files\R\R-3.2.2\bin folder.
Here's the beginning of my code.
using System.IO;
using System.Linq;
using RDotNet;
using RDotNet.NativeLibrary;
namespace RNetTest
{
class Program
{
static void Main(string[] args)
{
// Set the R_HOME environment variable in which R.dll is located.
Environment.SetEnvironmentVariable("R_HOME", @"C:\Program Files\R\R-3.2.2\bin\i386");
REngine engine = REngine.GetInstance("RDotNet");
It fails on the GetInstance with the error:
An unhandled exception of type 'System.ArgumentException' occurred in DynamicInterop.dll
Additional information: Could not retrieve a pointer for the symbol 'R_CStackLimit' in file 'RDotNet'
If I run REngine.GetInstance(); like is suggested I get the following error:
An unhandled exception of type 'System.Exception' occurred in DynamicInterop.dll
Additional information: This 32-bit process failed to load the library R.dll. Native error message is 'The system cannot find the file specified'
I've been wrestling with this for many hours now and finally asking for some help on what a solution might be. It should be noted the error is the same for 32bit or 64bit R.dll versions.
Comments: Alright, I dropped the utility code into the top of my project and here are the results. Is this process 64 bits? False Info: caller provided rPath=null, rHome=null Info: R.NET looked for preset R_HOME env. var. Found c:\Progra~1\R\R-3.2.2 I then get the following error when call GetInstance() System.Exception: This 32-bit process failed to load the library R.dll. Native error message is 'The specified module could not be found' at DynamicInterop.UnmanagedDll.ThrowFailedLibraryLoad(String dllFullName, String nativeError) at DynamicInterop.UnmanagedDll.ReportLoadLibError(String dllName, String nativeError) at DynamicInterop.UnmanagedDll..ctor(String dllName) at RDotNet.REngine..ctor(String id, String dll) at RDotNet.REngine.CreateInstance(String id, String dll) at RDotNet.REngine.GetInstance(String dll, Boolean initialize, StartupParameter parameter, ICharacterDevice device) at RNetTest.Program.Main(String[] args) in c:\Users\cmenright\Documents\Visual Studio 2013\Projects\RNetTest\RNetTest\Program.cs:line 35 Here is the code that I'm trying to run: // Call R from .NET. Advantage is that everything is in process. // Tested on VS2012, will probably work on VS2010. using System; using System.IO; using System.Linq; using RDotNet; using RDotNet.NativeLibrary; namespace RNetTest { class Program { static void Main(string[] args) { try { string rHome = null; string rPath = null; if (args.Length > 0) rPath = args[0]; if (args.Length > 1) rHome = args[1]; var logInfo = NativeUtility.FindRPaths(ref rPath, ref rHome); Console.WriteLine("Is this process 64 bits? {0}", System.Environment.Is64BitProcess); Console.WriteLine(logInfo); REngine.SetEnvironmentVariables(); REngine engine = REngine.GetInstance(); // Initializes settings. //engine.Initialize(); // .NET Framework array to R vector. NumericVector group1 = engine.CreateNumericVector(new double[] { 30.02, 29.99, 30.11, 29.97, 30.01, 29.99 }); engine.SetSymbol("group1", group1); // Direct parsing from R script. NumericVector group2 = engine.Evaluate("group2 <- c(29.89, 29.93, 29.72, 29.98, 30.02, 29.98)").AsNumeric(); // Test difference of mean and get the P-value. GenericVector testResult = engine.Evaluate("t.test(group1, group2)").AsList(); double p = testResult["p.value"].AsNumeric().First(); Console.WriteLine("Group1: [{0}]", string.Join(", ", group1)); Console.WriteLine("Group2: [{0}]", string.Join(", ", group2)); Console.WriteLine("P-value = {0:0.000}", p); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } } } I'm not sure what's going on but I've tried everything on this site as well as a few others on Google but I can't seem to get this working. Any other ideas?
Within Windows 7 I'm running R-3.2.2 and both 32bit and 64bit reside within my C:\Program Files\R\R-3.2.2\bin folder.
Here's the beginning of my code.
using System.IO;
using System.Linq;
using RDotNet;
using RDotNet.NativeLibrary;
namespace RNetTest
{
class Program
{
static void Main(string[] args)
{
// Set the R_HOME environment variable in which R.dll is located.
Environment.SetEnvironmentVariable("R_HOME", @"C:\Program Files\R\R-3.2.2\bin\i386");
REngine engine = REngine.GetInstance("RDotNet");
It fails on the GetInstance with the error:
An unhandled exception of type 'System.ArgumentException' occurred in DynamicInterop.dll
Additional information: Could not retrieve a pointer for the symbol 'R_CStackLimit' in file 'RDotNet'
If I run REngine.GetInstance(); like is suggested I get the following error:
An unhandled exception of type 'System.Exception' occurred in DynamicInterop.dll
Additional information: This 32-bit process failed to load the library R.dll. Native error message is 'The system cannot find the file specified'
I've been wrestling with this for many hours now and finally asking for some help on what a solution might be. It should be noted the error is the same for 32bit or 64bit R.dll versions.
Comments: Alright, I dropped the utility code into the top of my project and here are the results. Is this process 64 bits? False Info: caller provided rPath=null, rHome=null Info: R.NET looked for preset R_HOME env. var. Found c:\Progra~1\R\R-3.2.2 I then get the following error when call GetInstance() System.Exception: This 32-bit process failed to load the library R.dll. Native error message is 'The specified module could not be found' at DynamicInterop.UnmanagedDll.ThrowFailedLibraryLoad(String dllFullName, String nativeError) at DynamicInterop.UnmanagedDll.ReportLoadLibError(String dllName, String nativeError) at DynamicInterop.UnmanagedDll..ctor(String dllName) at RDotNet.REngine..ctor(String id, String dll) at RDotNet.REngine.CreateInstance(String id, String dll) at RDotNet.REngine.GetInstance(String dll, Boolean initialize, StartupParameter parameter, ICharacterDevice device) at RNetTest.Program.Main(String[] args) in c:\Users\cmenright\Documents\Visual Studio 2013\Projects\RNetTest\RNetTest\Program.cs:line 35 Here is the code that I'm trying to run: // Call R from .NET. Advantage is that everything is in process. // Tested on VS2012, will probably work on VS2010. using System; using System.IO; using System.Linq; using RDotNet; using RDotNet.NativeLibrary; namespace RNetTest { class Program { static void Main(string[] args) { try { string rHome = null; string rPath = null; if (args.Length > 0) rPath = args[0]; if (args.Length > 1) rHome = args[1]; var logInfo = NativeUtility.FindRPaths(ref rPath, ref rHome); Console.WriteLine("Is this process 64 bits? {0}", System.Environment.Is64BitProcess); Console.WriteLine(logInfo); REngine.SetEnvironmentVariables(); REngine engine = REngine.GetInstance(); // Initializes settings. //engine.Initialize(); // .NET Framework array to R vector. NumericVector group1 = engine.CreateNumericVector(new double[] { 30.02, 29.99, 30.11, 29.97, 30.01, 29.99 }); engine.SetSymbol("group1", group1); // Direct parsing from R script. NumericVector group2 = engine.Evaluate("group2 <- c(29.89, 29.93, 29.72, 29.98, 30.02, 29.98)").AsNumeric(); // Test difference of mean and get the P-value. GenericVector testResult = engine.Evaluate("t.test(group1, group2)").AsList(); double p = testResult["p.value"].AsNumeric().First(); Console.WriteLine("Group1: [{0}]", string.Join(", ", group1)); Console.WriteLine("Group2: [{0}]", string.Join(", ", group2)); Console.WriteLine("P-value = {0:0.000}", p); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } } } I'm not sure what's going on but I've tried everything on this site as well as a few others on Google but I can't seem to get this working. Any other ideas?