130 likes | 294 Views
Zurich. R with COM the dark side of .NET. john@mango-solutions.com. R with COM the dark side of .NET. Why I am talking about ‘nothing to do with R’ What are the issues with integrating R with other languages? The .NET paradigm Work done at codeplex A simple example done for free
E N D
Zurich R with COMthe dark side of .NET john@mango-solutions.com
R with COMthe dark side of .NET • Why I am talking about ‘nothing to do with R’ • What are the issues with integrating R with other languages? • The .NET paradigm • Work done at codeplex • A simple example done for free • Graphing
nothing to do with R • R solves difficult but particular problems • Enterprises have other issues • Integration with databases • R may be part of much larger developments • There is no concept of workflow
integrating R • R is late binding • Variable ‘types’ change at every step • Manages its own memory • Initial design as a pipe application, stdin, stdout (like sed etc.)
integrating R • The big problem is exchanging complex objects in memory • Strings are never a problem! • Vectors, matrices, lists must be mapped to concepts inj the host language • COM solves by creating is own process with R • Expensive! • Java integration solves by utilizing only static types • Need to know a lot about the data before • .NET introduces “marshalling” • An buffer area where data can be read/written between managed and un-managed code
.NET paradigm • (From Windows) • Event Handling • Common Run Time • Now towards its 4th incarnation • Good support for threading • security • Remoting • Diverse application languages • Adoption (and rejection) of new languages (e.g. J# and F#)
Events • Message passing paradigm including call-backs private void Application_Startup(object sender, StartupEventArgs e) { REngine.SetDllDirectory(@"C:\R\R-2.10.1\bin"); REngine.CreateInstance("RDotNet"); } private void Application_Exit(object sender, ExitEventArgs e) { REngine engine = REngine.GetInstanceFromID("RDotNet"); if (engine != null) { engine.Close(); } }
rdotnet.codeplex.com • Microsoft Project Hosting for Open Source Software • Implementation of R.h and Rinternals.h • Very impressive C# code • Currently only console device internal interface INativeMethodsProxy { intRf_initEmbeddedR(intargc, string[] argv); void Rf_endEmbeddedR(int fatal); IntPtrRf_protect(IntPtrsexp); void Rf_unprotect(int count); void Rf_unprotect_ptr(IntPtrsexp);
Conclusions • .NET provides a modern wrapper for making the best use of R • .NET can be developed for free • A full environment does cost a little • An open license without the R(D)COM constraints • Just as easy to integrate with Excel