Reputation: 21
I am getting an error same error when loading "dplyr" library.
engine.Evaluate("library(dplyr)");
Above code me same error
"An unhandled exception of type 'System.StackOverflowException' occurred in RDotNet.dll".
Can someone please help me? Thanks in advance...
Upvotes: 2
Views: 1256
Reputation: 1
I solved the crash issue by adding all R code to the new thread. It runs perfectly. In debug mode I can even see that the R code is evaluated correctly! Code below (it is in VB but easy to covert to C#). Plus I included some more context that may help.
The catch is, now that we are in another thread, I cannot access the UI thread. Seems there's a great way to accomplish this in Win Forms using a UI's Invoke method but webcontrols don't seem to have this method. Hope this helps some.
Public Class SPF_R
Inherits System.Web.UI.Page
Dim t As System.Threading.Thread
...
Private Sub RunRStuff()
Dim RCode As String = ""
Dim engine As REngine = REngine.GetInstance(Nothing, True, Nothing)
Dim myPath As String = ViewState("Folder") & ViewState("File")
engine.Initialize()
engine.Evaluate("library(MASS)") : RCode &= "library(MASS)" & vbCrLf
engine.Evaluate("library(ggplot2)") : RCode &= "library(ggplot)" & vbCrLf
engine.Evaluate("library(broom)") : RCode &= "library(broom)" & vbCrLf
...
End Sub
Private Function DevelopSPF() As Boolean
cmdSPF.Enabled = False
t = New System.Threading.Thread(AddressOf RunRStuff, 2500000)
t.Start()
cmdSPF.Enabled = True
Return True
End Function
...
Upvotes: 0
Reputation: 61
I had a similar issue with loading dplyr and other R libraries. Turns out of the issue is with IIS and IIS Express having stack size of 256K on 32-bit and 512 K on 64-bit OS as mentioned here. You can get around this by either:
1) Creating a thread with a larger stack size and executing the R.NET commands inside of it. For example:
Thread t = new Thread(MyMethodToDoRWork, 2500000 /*thread stack size of 2.5MB*/);
2) Change the default stack size of the IIS or IIS Express process via the EditBin tool (comes with Visual Studio). See the example here. I don't recommend this however as you will be modifying the actual IIS/IIS Express binary file.
Upvotes: 6