Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling .NET/C# from R

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?

like image 957
Dave Avatar asked Sep 13 '12 16:09

Dave


People also ask

Can I use .NET with C?

. NET Framework is an object oriented programming framework meant to be used with languages that it provides bindings for. Since C is not an object oriented language it wouldn't make sense to use it with the framework.

Is RestSharp better than HttpClient?

The main conclusion is that one is not better than the other, and we shouldn't compare them since RestSharp is a wrapper around HttpClient.

Can C++ call C#?

C++/CLI can call any C# function as if it were a "regular" C++ function. Add your references, /clr and It Just Works.


2 Answers

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.

like image 159
j-m Avatar answered Oct 17 '22 23:10

j-m


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.

like image 29
Tae-Sung Shin Avatar answered Oct 17 '22 23:10

Tae-Sung Shin