Multi-windows R graphs in C# with RDotNet -
Multi-windows R graphs in C# with RDotNet -
i have c# code simple windows form 3 buttons. button 1 calls r , plots surface while button 2 plots contour. if launch application , click on button 1, correctly see surface plot click on button 2 open new window counter plot. unfortunately, if seek app freezes , cannot go on. have added button 3 intention close r engine if running. thought kill r instance , reopen when clicking on button 2. doesn't work either. there way prepare problem?
using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.threading.tasks; using system.windows.forms; using rdotnet; namespace mysurface { public partial class form1 : form { public form1() { initializecomponent(); } public void button1_click(object sender, eventargs e) { string dllpath = @"c:\program files\r\r-3.1.0\bin\i386\"; rengine.setdlldirectory(dllpath); rengine.createinstance("rdotnet"); rengine engine = rengine.getinstancefromid("rdotnet"); if (engine.isrunning == false) { engine.initialize(); } var x = engine.evaluate("x <- 1:100").asnumeric(); var y = engine.evaluate("y <- 5:105").asnumeric(); engine.evaluate("model = function (a, b){23.86+5.525*b-2.5725*a-6.6413*b^2-5.1862*a^2}"); //evaluate function engine.evaluate("z = outer(x, y ,model)"); engine.evaluate("persp(x,y,z)"); //console.writeline(x[0]); } public void button2_click(object sender, eventargs e) { string dllpath = @"c:\program files\r\r-3.1.0\bin\i386\"; rengine.setdlldirectory(dllpath); rengine.createinstance("rdotnet"); rengine engine = rengine.getinstancefromid("rdotnet"); if (engine.isrunning == false) { engine.initialize(); } var x = engine.evaluate("x <- 1:100").asnumeric(); var y = engine.evaluate("y <- 5:105").asnumeric(); engine.evaluate("model = function (a, b){23.86+5.525*b-2.5725*a-6.6413*b^2-5.1862*a^2}"); //evaluate function engine.evaluate("z = outer(x, y ,model)"); engine.evaluate("contour(x,y,z, nlevels = 10)"); //console.writeline(x[0]); } private void button3_click(object sender, eventargs e) { rengine engine = rengine.getinstancefromid("rdotnet"); if (engine.isrunning == false) { engine.close(); } } }
}
you seem using r.net 1.5.5 or less. latest version 1.5.16 , initialisation procedure different. answer recent post on stackoverflow provides more details. issues attempts @ multiple initialisations of r tipycally used lead symptoms describe, , new api tries prevent this.
c# r charts windows-forms-designer rdotnet
Comments
Post a Comment