Could not load file or assembly 'RDotNet, Version=1.5.4.0

Sep 10, 2013 at 7:32 PM
Hello.

I'm a new C# user trying to get R.NET working in Linux. I just copied one of the examples from this page to see if it works, but I think I am making some mistakes on setting the directories because I keep getting this error:
Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'RDotNet, Version=1.5.4.0, Culture=neutral, PublicKeyToken=5f72f6e23c6920d4' or one of its dependencies.
File name: 'RDotNet, Version=1.5.4.0, Culture=neutral, PublicKeyToken=5f72f6e23c6920d4'
[ERROR] FATAL UNHANDLED EXCEPTION: System.IO.FileNotFoundException: Could not load file or assembly 'RDotNet, Version=1.5.4.0, Culture=neutral, PublicKeyToken=5f72f6e23c6920d4' or one of its dependencies.
File name: 'RDotNet, Version=1.5.4.0, Culture=neutral, PublicKeyToken=5f72f6e23c6920d4'
Any advice? Here is the original code exactly:
using System;
using System.IO;
using System.Linq;
using RDotNet;

class Program
{

    static void Main(string[] args)
    {
          string PATH = @"/home/parker/.R.NET";
          // Set the folder in which R.dll locates.
          var envPath = Environment.GetEnvironmentVariable(PATH);
          var rBinPath = @"/usr/lib/R/lib";
            var R_HOME = @"/usr/lib/R";
          Environment.SetEnvironmentVariable(PATH, envPath + Path.PathSeparator + rBinPath);
          using (REngine engine = REngine.CreateInstance("RDotNet"))
          {
              // 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);
          }
    }
}
I compiled using this command:
dmcs /reference:/home/parker/.R.NET/RDotNet Rtest.cs
Developer
Sep 11, 2013 at 7:58 AM
Hi,

I'll probably have to work with R.NET in the near future; I'll have a quick look at your issue as soon as I can and get back to you.

Regards.
Sep 11, 2013 at 4:15 PM
Thank you. One thing I forgot to mention is that the file compiles fine and the error comes up on trying to run the .exe file.
Developer
Sep 11, 2013 at 10:58 PM
Your setting up of the environment variables PATH and R_HOME is incorrect. It should be something like:
            var envPath = Environment.GetEnvironmentVariable ("PATH");
            var rBinPath = @"/usr/lib/R/lib";
            Environment.SetEnvironmentVariable ("R_HOME", @"/usr/lib/R");
            Environment.SetEnvironmentVariable ("PATH", envPath + Path.PathSeparator + rBinPath);
Sep 12, 2013 at 12:19 AM
Thanks! It looks like I also had an error in the command line compile code. It should be the relative location of the file. I moved those dlls into the directory with my program and the new compile code looks like this.
dmcs /r:RDotNet.dll Rtest.cs
Thanks for your help. This is a great project!