Get R Valuation Results Using R.Net

I am using R.Net 1.5 to attempt a simple forecast using ARIMA. I tried with R 2.14 and R 2.15. I am using Visual Studio 2012 target .NET 4, although I also tried .NET 4.5 and Visual Studio 2010.

Here is a piece of code that I wrote:

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();

An attempt to get a numeric vector failed. Here I get a few errors. The first is "Error: the object cannot be forced to type" double ", and the second is" Error: an access violation was detected - continue with caution "

GenericVector, RDotNet.SymbolicExpressions. , , , , ARIMA, . , , , .

script , , , , R.Net . , . R.Net , Revolution ( , ), genericvector .

GenericVector. , : DynamicVector .

GenericVector newVector = engine.GetSymbol("fcast").AsList();

            foreach (var vector in newVector)
            {
                try
                {
                    DynamicVector dv = vector.AsVector();
                }
                catch (Exception)
                {
                }
+5
1

R.Net, script. R:

> testTs <- c(1, 2, 3)
> tsValue <- ts(testTs, frequency=1, start=c(2010, 1, 1))
> library("forecast")
> arimaFit <- auto.arima(tsValue)
> fcast <- forecast(tsValue, h=36)
> plot(fcast)

class(fcast) forecast:

> class(fcast)
[1] "forecast"
> as.numeric(fcast)
Error: (list) object cannot be coerced to type 'double'

fcast strucure:

> str(fcast)
List of 11
 $ method   : chr "Mean"
 $ level    : num [1:2] 80 95
 $ x        : Time-Series [1:3] from 2010 to 2012: 1 2 3
 $ xname    : chr "object"
 $ mean     : Time-Series [1:36] from 2013 to 2048: 2 2 2 2 2 2 2 2 2 2 ...
 $ lower    : mts [1:36, 1:2] -0.177 -0.177 -0.177 -0.177 -0.177 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : NULL
  .. ..$ : chr [1:2] "80%" "95%"
  ..- attr(*, "tsp")= num [1:3] 2013 2048 1
  ..- attr(*, "class")= chr [1:2] "mts" "ts"
 $ upper    : mts [1:36, 1:2] 4.18 4.18 4.18 4.18 4.18 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : NULL
  .. ..$ : chr [1:2] "80%" "95%"
  ..- attr(*, "tsp")= num [1:3] 2013 2048 1
  ..- attr(*, "class")= chr [1:2] "mts" "ts"
 $ model    :List of 4
  ..$ mu   : num 2
  ..$ mu.se: num 0.577
  ..$ sd   : num 1
  ..$ call : language meanf(x = object, h = h, level = level, fan = fan)
 $ lambda   : NULL
 $ fitted   : Time-Series [1:3] from 2010 to 2012: NA 1 1.5
 $ residuals: Time-Series [1:3] from 2010 to 2012: NA 1 1.5
 - attr(*, "class")= chr "forecast"
+5

All Articles