开发者

How to call an SDK provided as a C# .net COM dll file in R

开发者 https://www.devze.com 2023-01-31 15:22 出处:网络
I would describe myself as an intermediate R user, but a total C/C+/C# novice.My current task involves pulling data out of a commercial system using the vendors provided SDK.This is provided as a dll

I would describe myself as an intermediate R user, but a total C/C+/C# novice. My current task involves pulling data out of a commercial system using the vendors provided SDK. This is provided as a dll file and I also have some documentation and examples of C+ and C# code.

What is the best way to call these C functions from R and get the data in. Can anyone recomend some good (introductory) read开发者_StackOverflow社区ing material or examples ?


Having a vendor-supported SDK is a good first step. I have started from that point a few times.

One problem may be that the SDK could well be built with Visual Studio. As a general rule, it is very difficult to impossible to mix C++ code across different compilers (as the generated code will differ in the mangled function signatures). So probably no Rcpp for you here as you have compatible library to work with.

On the other hand, C can work. There are still some issues involved as you may have to create some additional files to make the Visual Studio-created library compatible with MinGW linker you have to use with R. Details are on the MinGW site. Now, C is arguably a more tedious interface than C++ but at least you stand a chance to make it work. I used this approach many years ago to connect R to the Bloomberg terminal backends using the Bloomberg C SDK (whereas the current RBloomberg package uses Java).

Lastly, C# and (D)COM route may work to but I have no experience in that matter.


You could do this as a two stage process. First, write a little C# program that retrieves the data from the dll (see, e.g., http://www.adp-gmbh.ch/csharp/call_dll.html) and writes it to a text file. Then import the data from the text file and analyse it in R.


Depending on the dll file (.NET or not), you may access its functions from within .NET. If you can't use .NET you will need interop to call the functions from within C#: http://msdn.microsoft.com/en-us/library/aa645736(v=vs.71).aspx

As for R and C#: here is a pointer for calling R from within C#: http://joachimvandenbogaert.wordpress.com/2009/03/26/r-and-c-on-windows/ As you may notice, I unfortunately haven't been maintaining this topic, as I switched to Java.

For a fully automated solution, you may call the SDK from within C# and pass it to the R connector for C#. For flexibility of your solution, I recommend making the R code in C# configurable.


Have a look at the Rcpp package - I haven't had a chance to try it myself yet, but it looks like a nice way of calling C++ from R

http://dirk.eddelbuettel.com/code/rcpp.html - or on cran

0

精彩评论

暂无评论...
验证码 换一张
取 消