R with COM the dark side of .NET
Download
Report
Transcript R with COM the dark side of .NET
Zurich
R with COM
the dark side of .NET
[email protected]
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
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();
}
}
XAML and ‘code-behind’
rdotnet.codeplex.com
Microsoft Project Hosting for Open Source Software
Implementation of R.h and Rinternals.h
internal interface INativeMethodsProxy
{
int Rf_initEmbeddedR(int argc, string[] argv);
void Rf_endEmbeddedR(int fatal);
IntPtr Rf_protect(IntPtr sexp);
void Rf_unprotect(int count);
void Rf_unprotect_ptr(IntPtr sexp);
Very impressive C# code
Currently only console device
Classes in R.NET bridges between R
and .NET Framework.
R
R.NET
.NET Framework
character vector
RDotNet.CharacterVector
System.String[]
integer vector
RDotNet.IntegerVector
System.Int32[]
real vector
RDotNet.NumericVector
System.Double[]
complex vector
RDotNet.ComplexVector
System.Numerics.Complex[]
raw vector
RDotNet.RawVector
System.Byte[]
logical vector
RDotNet.LogicalVector
System.Boolean[]
character matrix
RDotNet.CharacterMatrix
System.String[, ]
integer matrix
RDotNet.IntegerMatrix
System.Int32[, ]
real matrix
RDotNet.NumericMatrix
System.Double[, ]
complex matrix
RDotNet.ComplexMatrix
System.Numerics.Complex[, ]
raw matrix
RDotNet.RawMatrix
System.Byte[, ]
logical matrix
RDotNet.LogicalMatrix
System.Boolean[, ]
Note
The minimum value in R is 2^31+1 while that of .NET
Framework is -2^31.
System.Numerics assembly is
required for .NET Framework 4.
The minimum value in R is 2^31+1 while that of .NET
Framework is -2^31.
System.Numerics assembly is
required for .NET Framework 4.
A simple example done for free
Graphing
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