R.Net doesn't load library("lattice")

Oct 12, 2014 at 12:15 AM
Hi, I am calling R from C# uding R.Net but I would need to load the library Lattice to generate some graphs.
I downloaded the library from RStudio.
In order to make C# call R I had to put the R.dll into my C# application project folder.

If I run the code it fails probably because cannot load the library Lattice.

Is the anything to do to make R.Net recognize that I have the library installed?

Should I move some dll? Does the library have a dll?
Oct 14, 2014 at 7:39 PM
Did you install the package using the R client, on the machine in question? Also, have you added the location of the R software to your SYSTEM directory (Environment variable)? I had the same issues with all packages and after adding the folder to my SYSTEM directory most everything was cleared up. Anything that wasn't was due to it not being installed in R itself. Not sure if this is the same issue you're experiencing, but it's worth a try.

Oct 15, 2014 at 10:34 PM
Hi how should I add the location to the System directory?
I have moved R.dll in the folder where my C# project is stored. Then I use the following:
        REngine engine = REngine.GetInstance();

        var v1 = engine.CreateNumericVector(myX); /
        var v2 = engine.CreateNumericVector(myY);
        var v3 = engine.CreateNumericMatrix(myZ);

        engine.SetSymbol("v1", v1);
        engine.SetSymbol("v2", v2);
        engine.SetSymbol("v3", v3);

Apparently this works now. I was using wrong syntax. Anyway I still have the problem with ggplot2 library. I installed it via RStudio but I'm not able to use it.

Can you please show me how I can plot as line my variable v1? Thanks for the help.
Oct 17, 2014 at 6:58 PM
You'll need to add the following to the end of the environment variable: "Path" ;C:\Program Files\R\R-3.1.1\bin\i386;C:\Program Files\R\R-3.1.1\bin\x64;

Sorry, I was incorrect on the previous post, it's not the system but the "Path" environment variable. You may only need the i386 if you're not on a 64-bit machine, but I am so I included both. This way the system will handle where R is and execute it.

As for the ggplot2 library, is that installed via the R-Client? Let me know if adding R to your path helps this to run correctly. You shouldn't need the R.dll in your project folder after the path is updated.


Oct 21, 2014 at 5:49 PM
Hi, here is the code I am using:
    public void plotGraphR_2D(List<double> x, double[,] y)
        string Rpath = @"C:\Program Files\R\R-3.1.0\bin\x64";

        REngine engine = REngine.GetInstance();

        var v1 = engine.CreateNumericVector(x);
        var v2 = engine.CreateNumericMatrix(y);

        if (engine.IsRunning == false)

        engine.SetSymbol("v1", v1);
        engine.SetSymbol("v2", v2);

        engine.Evaluate("my_data <- data.frame(v2)");
        engine.Evaluate("colnames(my_data) <- c('Price', 'Quantity')");
        engine.Evaluate("myChart <- ggplot() + geom_line(data = my_data, my_data$Price)"); // THIS DOESN'T WORK
        //engine.Evaluate("plot(my_data$Price)"); // THIS WORKS
My input x is a list while y is a 2 dimensional array. I first convert x to numeric vector and y to data frame, then change column names to the data frame.
I want to plot one of the column of my data frame (my_data$Price) but when using ggplot2 it doesn't work. I don't get any error but I don't see any chart.
If I try using the last line engine.Evaluate("plot(my_data$Price)") so normal plot, it works fine.
Is there any problem with the way I call ggplot2? I have installed the library with RStudio. Anything else I should do to fix the issue?

Oct 22, 2014 at 12:29 PM
The behavior you are seeing is an intentional behavior with R. You need to surround
ggplot() + ggplot() + geom_line(data = my_data, my_data$Price)
print(ggplot() + ggplot() + geom_line(data = my_data, my_data$Price))
More information can be found from the R project website's R Internals document here: