We help IT Professionals succeed at work.

DLLNotFoundException with R.NET (Visual Studio 2010)

AndyC1000
AndyC1000 used Ask the Experts™
on
Hello,

I'm having trouble setting up and running this example from http://rdotnet.codeplex.com/. I keep on running into a DLLNotFoundException and I'm not sure what else to check.

I downloaded the dll "R.NET" from their website.  

Added it to my project as a reference.

Installed R and created a R_HOME environment variable.

Try to run the example and the exception occurs.

So I tried looking at the sub block of code below. In the example the instance of R is named RDotNet, I also tried R.NET it didn't work.

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

Open in new window


using System;
using System.Linq;
using RDotNet;


namespace RNetExample
{
    public class Program
    {

        static void Main(string[] args)
        {
          
            System.Environment.SetEnvironmentVariable("R_HOME", "C:\\Program Files\\R\\R-2.15.0\\bin");
            // Set the folder in which R.dll locates.
            REngine.SetDllDirectory(@"C:\LIB\DLL");

            Console.WriteLine(System.Environment.GetEnvironmentVariable("R_HOME"));

            try
            {
               using (REngine engine = REngine.CreateInstance("RDotNet", new[] {""}))  // quiet mode
              //using (REngine engine = REngine.CreateInstance("R.NET", new[] { "-q" }))  // quiet mode
                {
                    // .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.EagerEvaluate("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.EagerEvaluate("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(DllNotFoundException e)
            {
                Console.WriteLine("DLL not found in location");
            }
            
        }
    }
}

Open in new window



Not sure what else to try.  I was unable to find a more suitable topic area for the post.

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
i think this is where you should load your r.dll file from:-

REngine.SetDllDirectory(@"C:\Program Files\R\R-2.15.0\bin");

Author

Commented:
I moved the R.NET dll into the bin folder described above and re-inserted the reference from this location.  Still no change.