REngine rengine = REngine.CreateInstance(“RDotNet”

2019-07-26 17:03发布

问题:

I am plotting the forecast graph by using R.NET and using ASP.NET MVC3. At first time, it creates an instance of RENgine. by

REngine rengine = REngine.CreateInstance("RDotNet", new[] { "-q" })

and plots the graph as required. But when I call this same method second time by choosing another graph to be plotted, it stops to move further after this,. Please someone help me to figure out where I am going wrong. The code I have used is

using (REngine rengine = REngine.CreateInstance("RDotNet", new[] { "-q" }))
    {
        rengine.EagerEvaluate("YrTimeSeries<-c(123,234,255,456)");
        rengine.EagerEvaluate("tsValue<-ts(YrTimeSeries,frequency=1," 
                               + dt_StartYr.Rows[0][0].ToString() + ")");
        rengine.EagerEvaluate("library(Cairo);");
        rengine.EagerEvaluate("library(forecast)");
        rengine.EagerEvaluate(@"CairoPNG('C:\\Documents and Settings\\a\\im.png);
        rengine.EagerEvaluate("plot(forecast(tsValue,h=5),main='Immunization')");
        rengine.EagerEvaluate("graphics.off();");
        rengine.Close();
        rengine.Dispose();

    }
}

回答1:

I'm just reposting a comment that I had made about where to find the issue, but as everyone knows you don't get points for upvotes on comments.

Check out this MSDN on R.NET in parallel. I know you are not creating two at once, but it looks like this leads to exactly your same issue.