I am using R.Net 1.5 to attempt to do a simple forecast using ARIMA. I've tried with R 2.14 and R 2.15. I'm using Visual Studio 2012 target .NET 4 though I've also tried .NET 4.5 and Visual Studio 2010.
Here is a piece of the code I've written:
string rhome = System.Environment.GetEnvironmentVariable("R_HOME");
if (string.IsNullOrEmpty(rhome))
rhome = @"C:\Program Files\R\R-2.14.0";
System.Environment.SetEnvironmentVariable("R_HOME", rhome);
System.Environment.SetEnvironmentVariable("PATH", System.Environment.GetEnvironmentVariable("PATH") + ";" + rhome + @"\bin\x64");
using (REngine engine = REngine.CreateInstance("RDotNet"))
{
engine.Initialize();
NumericVector testGroup = engine.CreateNumericVector(submissions);
engine.SetSymbol("testGroup", testGroup);
engine.Evaluate("testTs <- c(testGroup)");
NumericVector ts = engine.GetSymbol("testTs").AsNumeric();
engine.Evaluate("tsValue <- ts(testTs, frequency=1, start=c(2010, 1, 1))");
engine.Evaluate("library(forecast)");
engine.Evaluate("arimaFit <- auto.arima(tsValue)");
engine.Evaluate("fcast <- forecast(tsValue, h=36)");
engine.Evaluate("plot(fcast)");
NumericVector nv = engine.GetSymbol("fcast").AsNumeric();
It fails when I attempt to retrieve the numeric vector. TI get a few errors here. The first is "Error: object cannot be coerced to type 'double'" and the second is "Error: caught access violation - continue with care"
If I retrieve the forecast as a GenericVector I get a list of RDotNet.SymbolicExpressions. I've looped through those to see what they contain and it does seem to be related to the ARIMA function but I cannot locate the actual forecast output. I can find the inputs and other related values as well as a bunch of lists of numbers that I can't determine what they are.
If I run the script within Revolution I can see what the outputs SHOULD be and that is how I'm determining whether the outputs from R.Net are accurate. I suppose it's possible R.Net is performing the forecast differently than Revolution (though unlikely, I think) and one of the outputs in the genericvector is indeed the correct output.
Here is the GenericVector initialization. I wrapped in a blanket try, catch just for debugging purposes: Inside the DynamicVector is where I can actually inspect the details.
GenericVector newVector = engine.GetSymbol("fcast").AsList();
foreach (var vector in newVector)
{
try
{
DynamicVector dv = vector.AsVector();
}
catch (Exception)
{
}