Can't get sample to run.

Mar 17, 2015 at 11:16 AM
Edited Mar 18, 2015 at 8:58 PM
Folks,

I am trying to run some of the sample code (see below) but I am not having any luck.

Let me know if there are other pieces of information that might help you help me.

I am using Microsoft Visual Studio 2013.

Thanks in advance,
KW

CODE:

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

namespace R.NET.Test
{
class Program
{
    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();
    }
}
}


ERROR MESSAGES:

Here are the error messages:

Warning 1 The 'packages' element is not declared. Z:\VisualStudioProjects\R.NET.Test\R.NET.Test\R.NET.Test\packages.config 2 2 R.NET.Test
Error 2 The name 'REngine' does not exist in the current context z:\visualstudioprojects\r.net.test\r.net.test\r.net.test\program.cs 13 13 R.NET.Test
Error 3 The type or namespace name 'REngine' could not be found (are you missing a using directive or an assembly reference?) z:\visualstudioprojects\r.net.test\r.net.test\r.net.test\program.cs 14 13 R.NET.Test
Error 4 The name 'REngine' does not exist in the current context z:\visualstudioprojects\r.net.test\r.net.test\r.net.test\program.cs 14 30 R.NET.Test
Error 5 The type or namespace name 'CharacterVector' could not be found (are you missing a using directive or an assembly reference?) z:\visualstudioprojects\r.net.test\r.net.test\r.net.test\program.cs 16 13 R.NET.Test


CONFIG
Here is packages.config:

<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="DynamicInterop" version="0.7.4" targetFramework="net45" />
<package id="R.NET.Community" version="1.5.21" targetFramework="net45" />
</packages>


HELP PLEASE :)
Developer
Mar 21, 2015 at 10:42 PM
Looks like you need to set up NuGet, and/or then restore the R.NET NuGet packages.

Please read the documentation , under "Getting set up", "Visual Studio"
Mar 22, 2015 at 12:38 AM
JP Thanks for the help. I have gone through a couple of iterations over the last week. I think it was earlier when I figured out that I needed to have "using RDotNet;” That wasn’t clear to me in the original example because I am new to C#. I am slowly
getting a handle on it. Have you built any applications that use R, RDOTNET and Excel? Anything tricky to worry about? Thanks again, Best, KW