Skip to Content

Calling R-UDF's from Excel

I want to have functions in Excel (Taking Excel-Arguments) that call R-Functions and return the results back to Excel. RExcel does not seem to be on CRAN (anymore) and I have not yet found an alternative. Does anyone know of a way to achieve this?

One constraint is that the solution should work even without administrator privileges on Windows Vista.

Thanks for the comment. We have tried R.Net, but with little success. We went for:

using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ExcelDna.Integration;
using System.Windows.Forms;
using RDotNet;
using RDotNet.NativeLibrary;
public static class MyFunctions
    [ExcelFunction(Description = "Test R connection")]
        public static double MyRTest(double x)
            var envPath = Environment.GetEnvironmentVariable("PATH");
            var rBinPath = @"D:\Programme\R\R-2.15.1\bin\i386";
            Environment.SetEnvironmentVariable("PATH", envPath + Path.PathSeparator + rBinPath);
            // using (REngine engine = REngine.CreateInstance("RDotNet"))
            // {
            // }
            // REngine rengine = REngine.CreateInstance("RDotNet");
            return (2*x);
        } // End Function
    [ExcelFunction(Description="Multiplies two numbers", Category="Useful functions")]
    public static double MultiplyThem(double x, double y)
        return x * y;

The function MultiplyThem() can be Called in Excel and it works. As is, so does MyRTest. But as soon as I try to instanciate R using either of the methods commented out, it returns the #Value error in Excel. Trying to make sense of it, we went for a Command Line application and just copied the example from here (v1.5). However at the line engine.Initialize(); the debugger just terminated, without error or exception. We use R12.15.1 (32 Bit), Windows Vista (32 Bit), Visual Studio 2010 Professional and RdotNet 1.5.0. What could have gone wrong?