I am developing a C# solution to run R.net (version 1.6.5) on a Windows server 2008 R2. The R functionality runs pretty stable and performs well. My Problem is that the server is running constantly, but R won't be needed all the time so in order to keep the maintenance simple I’d like to implement a Routine that starts the REngine , runs the R code and then shuts the REngine down again, so it can later be restarted. To shut down/idle the REngine temporarily the function Dispose() seems not to be appropriate as is prevents the REngine from restarting again. However the Rdotnet documentation also recommends to always shutdown an engine after using it. I tried using Dispose() but got different exeptions, in different usage cases one of them is:
The single REngine instance has already been disposed of (i.e. shut down). Multiple engine restart is not possible.My R initialization in C# currently looks like this:
class RDotNetAdaptor {
protected REngine REngine;
protected RDotNetAdaptor() {
REngine = REngine.GetInstance();
REngine.Initialize();
}
~RDotNetAdaptor() {
REngine.Dispose();
}
//…
}
How can I shut down/ idle the REngine so I can restart it again later?