Modi
Modi

Reputation: 143

Exception while using R Engine in Rdotnet

I have installed R.NET.Communityvia NuGet Package manager and added the following code (to get things started) but I keep getting error at the Rengine.SetEnvironmentVariables() line; the code does not even go forward.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RDotNet;

namespace WF_CRM_R
{
    public class CrmLogic
    {
        public void GetCrmOutput(Dictionary<int, List<double>> crmInput)
        {
            REngine.SetEnvironmentVariables();
            REngine engine = REngine.GetInstance();

            double[,] input = new double[crmInput[0].Count, crmInput.Count];

            for (int i = 0; i < crmInput.Values.Count; i++)
            {
                for (int j = 0; j < crmInput.Count; j++)
                {
                    input[i, j] = crmInput[crmInput.Keys.ElementAt(i)].ElementAt(j);
                }
            }
            var rMatrix = engine.CreateNumericMatrix(input);
            engine.SetSymbol("my.data.matrix.inj", rMatrix);
            engine.Evaluate("source('D:/R/Learning R/CRM_TestData_R_Ver5.R')");
            var output = engine.GetSymbol("my.data.matrix.inj").AsNumeric();
        }
    }
}

The error screenshot is here. enter image description here

This is a simple test Rdotnet and I can't fathom what's wrong!

Upvotes: 0

Views: 567

Answers (1)

SynerCoder
SynerCoder

Reputation: 12786

I took a quick dive into the documentation from R.NET and found the following:

SetEnvironmentVariables, on Windows, looks at the Registry settings set up by the R installer.

So from this I gather that you need to first install R before you can use R.NET. My guess is that R itself is not installed (properly).

Upvotes: 1

Related Questions