14

I'd like to use an API from R that is only available in .NET. Is there a standard method that can be used to call .NET C# code from R? If so, how can I do so?

Dave
  • 2,376
  • 1
  • 19
  • 37

2 Answers2

14

Another option that readers of this discussion might consider is the rClr package, which I have been working on for a couple of years to access arbitrary .NET code from R. It is a sibling of R.NET which, conversely, is a way to access R from .NET.

To give a flavour of the rClr package, the canonical "Hello World" looks like:

library(rClr)
clrLoadAssembly('c:/path/to/myassembly.dll')
myObj <- clrNew('MyNamespace.MyClass,MyAssemblyName')
clrCall(myObj, 'SayHelloWorld')

Feedback and suggestions welcome via the web site.

Jeremy Thompson
  • 57,045
  • 27
  • 167
  • 292
j-m
  • 1,253
  • 1
  • 11
  • 16
3

Exposing the .NET dll as COM dll and then calling a COM object in the dll from R seem to be the only way. And there is a package for it: http://cran.r-project.org/web/packages/rcom/rcom.pdf

If you cannot make a COM dll because it's third-party dll, you can always create a new interface-like .NET dll with COM interface where you can call actual dll.

Tae-Sung Shin
  • 19,749
  • 32
  • 136
  • 235
  • 1
    To get a list of ProgID's in the system, see http://procbits.com/2010/11/08/get-all-progid-on-system-for-com-automation/ – Contango Feb 05 '13 at 10:02