To use R in  C# , 
need  “RdotNet Library” to be added to the Visual Studio (by Nuget package manager).
Here you can find installation information:


Use R.NET (I installed mine from NuGet) and the following code in a new C# console app (which was copied with minor changes from

It will work when pointed at the 32-bit version of R v2.11.1, but it will not work when pointed at the 64-bit version of R v2.11.1 (as noted in the code below).

When I installed NuGet, it automatically added references to the current project: RDotNet (RDotNet.dll) and RDotNet.NativeLIbrary (RDotNet.NativeLibrary.dll). You’ll need these references in any new project.

Works under VS2012 (untested under VS2010, but will probably work).

Works when compiled for both “x32” and “All CPU” (under “Build..Configuration Manager” in VS2012).

// 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;
class Program
    static void Main(string[] args)
        // Set the folder in which R.dll locates.
        var envPath = Environment.GetEnvironmentVariable("PATH");
        var rBinPath = @"C:\Program Files (x86)\R\R-2.11.1\bin";
        //var rBinPath = @"C:\Program Files\R\R-2.11.1-x64\bin"; // Doesn't work ("DLL was not found.")
        Environment.SetEnvironmentVariable("PATH", envPath + Path.PathSeparator + rBinPath);
        using (REngine engine = REngine.CreateInstance("RDotNet"))
            // Initializes settings.

            // .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);





Stat in C# without R



R (D)COM Server and RExcel
This package contains a DCOM server used to connect a client application (e.g. Microsoft Excel) with R.

R (D)COM Server provides a COM-Interface to R as well as various COM objects and Active X controls for your applications. Additionally, an Add-In for Microsoft Excel is provided to easily use R in Excel and create statistical applications with Excel as the main GUI. The main features of this package are:

-COM server for local and remote use of R
-transfer of data into/from R, including NA, NaN,…
-Active X Controls for text and graphics output
-Repository for R instances for shared and exclusive access
-Many Samples
-Excel Add-In

Is commercial now:

Thomas Baier and Erich Neuwirth



meta numerics

library features include advanced functions, function analysis (solvers), statistics and data analysis, linear algebra, and Fourier transforms.


Since 11 April 2023: 1,493 total views,  34 views today