Properly Closing and Unloading the RDotNet Engine.

Jan 24 at 10:19 PM

I'm Opening the REngine like this

			console = new RDotNet.Devices.ConsoleDevice();
			REngine.SetDllDirectory(@"C:\Program Files\R\R-2.12.1\bin\i386");
			engine = REngine.CreateInstance("RDotNet",console);

 

then doing a bunch of R commands that works successfully.

 

Finally I close the engine like this:

			engine.Close();
			engine.Dispose();

If I repeat the same procedure again, I get a crash from the same R commands that previously worked (In this case the engine can't find the "ts()" function).

I'm lead to believe that this is problem with loading, unloading and reloading the REngine. Any tips?

 

Thanks

Jan 26 at 4:41 PM

I'm seeing exactly the same issue here.

 

Getting an SEHException when running working code for the second time.  I've looked in the Dispose method and this line:

Proxy.Rf_endEmbeddedR(0);

In the REngine.cs class is never hit:

        protected override void Dispose(bool disposing)
        {
            if (instances.ContainsKey(ID))
            {
                instances.Remove(ID);
            }

            if (IsRunning)
            {
                if (disposing)
                {
                    Proxy.Rf_endEmbeddedR(0);
                }
                proxy = null;
                if (adapter != null)
                {
                    adapter.Dispose();
                    adapter = null;
                }
            }

            base.Dispose(disposing);
        }

I'm currently assigned to get this working asap for a current project.  If you make any progress let me know and I'll do the same.

Seems this has been a problem for a number of people for a while now.


Regards,

Jan 27 at 9:09 AM

One thing I have noticed is if you are seeing these crashes during testing you may actually be worrying about false positives.

For instance if you are running NUnit and Test Driven dot net you need to end the ProcessInvocation86.exe process between test runs.  Hopefully more to follow!

Feb 27 at 5:45 AM
Edited Feb 27 at 7:20 AM

I am also having still problem, and this is critical for me: I have to manage creation and destruction of instances of class RDotNet many times because my code runs as a plugin and is launched by mainapp each time in different appdomain. 

My env: Vista, x86, R-Community-5.0 (R 2.13.2), .NET 3.5/4.0

My code in windows forms simple app is like this:

 

private void button7_Click(object sender, EventArgs e)        
{

          string sRHome = FindRPath();           

          System.Environment.SetEnvironmentVariable("PATH",
System.Environment.GetEnvironmentVariable("PATH") + ";" + sRHome);
          REngine.SetDllDirectory(sRHome);

          using (REngine engine = REngine.CreateInstance("RDotNet"))            
          {               

              NumericVector random = 
engine.EagerEvaluate("rnorm(5, 0, 1)").AsNumeric(); } }

 

Works fine first time. Second time it hangs on the line with EagerEvaluate() call consuming CPU 100%. I have tried to check if bug persists: tested with R.NET 1.3 for .NET 3.5 and built latest source R.NET 1.4.1 for .NET 4.0. The problem persists. 
I would like to ask author kos59125 to advise on this. Is there a way to fix this problem? Anyone has found some workarounds? Thank you.

Apr 14 at 11:19 AM

Tested new version of R.NET as of 14.04.2012. The bug persists. I create and init new instance of R.NET. Make calculations. Close and destroy it. Open new instance - system hangs with 100% CPU on .Initialize() method.

Apr 27 at 8:21 AM

I have the same issue. Anyone can help? Thanks

May 2 at 12:01 PM
Edited May 2 at 12:26 PM

Okay with some testing I got the REngine properly "destroyed" with:

 

If Not IsNothing(engine) then
engine.SetHandleAsInvalid
engine.close
else
REngine.SetDllDirectory(dlldirectory)
engine = REngine.CreateInstance("RDotNet", {"-q"}
End If

 

It might be far away from any substantial proof but it is working somehow!

Hope to be able to help you guys!