Exception at REngine.SetEnvironmentVariables() call

Viewed 1799

I am getting an exception at REngine.SetEnvironmentVariables() in my below code, may I know how can I check the environment variables are set correctly.

static void Main(string[] args)
    {
        REngine.SetEnvironmentVariables(); // <-- May be omitted; the next line would call it.

        REngine engine = REngine.GetInstance();
        // A somewhat contrived but customary Hello World:
        CharacterVector charVec = engine.CreateCharacterVector(new[] { "Hello, R world!, .NET speaking" });
        engine.SetSymbol("greetings", charVec);
        engine.Evaluate("str(greetings)"); // print out in the console
        string[] a = engine.Evaluate("'Hi there .NET, from the R engine'").AsCharacter().ToArray();
        Console.WriteLine("R answered: '{0}'", a[0]);
        Console.WriteLine("Press any key to exit the program");
        Console.ReadKey();
        engine.Dispose();
    }

Visual studio Exception

2 Answers

Old thread but in case anyone else has this problem: REngine.SetEnvironmentVariables() needs two paramters (the second one being Rs "outer" home directory), so based on David's answer I used

REngine.SetEnvironmentVariables("C:\\Program Files\\R\\R-3.2.3\\bin\\i386","C:\\Program Files\\R\\R-3.2.3");

and it works. It seems that REngine.SetEnvironmentVariables tries to read this from the registry anyways - in my case I don't have admin rights on the computer and while R itself works fine these values were not written to the registry during installation.

Related