如何在 R 中调用作为 C# .net COM dll 文件提供的 SDK

发布于 2024-10-07 22:57:08 字数 170 浏览 0 评论 0原文

我将自己描述为中级 R 用户,但完全是 C/C+/C# 新手。我当前的任务涉及使用供应商提供的 SDK 从商业系统中提取数据。这是作为 dll 文件提供的,我还有一些 C+ 和 C# 代码的文档和示例。

从 R 调用这些 C 函数并获取数据的最佳方法是什么?任何人都可以推荐一些好的(介绍性)阅读材料或示例吗?

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) reading material or examples ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

彩虹直至黑白 2024-10-14 22:57:08

拥有供应商支持的 SDK 是良好的第一步。我已经从这一点开始好几次了。

一个问题可能是 SDK 很可能是用 Visual Studio 构建的。作为一般规则,在不同编译器之间混合 C++ 代码是非常困难甚至不可能的(因为生成的代码在损坏的函数签名中会有所不同)。因此,这里可能没有 Rcpp 供您使用,因为您有兼容的库可以使用。

另一方面,C 可以工作。仍然存在一些问题,因为您可能需要创建一些额外的文件,以使 Visual Studio 创建的库与您必须与 R 一起使用的 MinGW 链接器兼容。详细信息位于 MinGW 站点上。现在,C 可以说是一个比 C++ 更乏味的接口,但至少你有机会让它工作。许多年前,我使用这种方法使用 Bloomberg C SDK 将 R 连接到 Bloomberg 终端后端(而当前的 RBloomberg 包使用 Java)。

最后,C# 和 (D)COM 路线可能有效,但我在这方面没有经验。

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.

若相惜即相离 2024-10-14 22:57:08

您可以将其作为两个阶段的过程来完成。首先,编写一个小 C# 程序,从 dll 检索数据(例如,参见 http: //www.adp-gmbh.ch/csharp/call_dll.html)并将其写入文本文件。然后从文本文件导入数据并在 R 中进行分析。

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.

心清如水 2024-10-14 22:57:08

根据 dll 文件(是否为 .NET),您可以从 .NET 中访问其函数。如果您无法使用 .NET,则需要互操作来从 C# 中调用函数:http://msdn.microsoft.com/en-us/library/aa645736(v=vs.71).aspx

对于 R 和 C#:这是一个用于调用的指针C# 中的 R:http://joachimvandenbogaert.wordpress .com/2009/03/26/r-and-c-on-windows/ 正如您可能注意到的,不幸的是,由于我转向了 Java,所以我没有一直维护这个主题。

对于完全自动化的解决方案,您可以从 C# 中调用 SDK,并将其传递到 C# 的 R 连接器。为了提高解决方案的灵活性,我建议使用 C# 来配置 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.

人间不值得 2024-10-14 22:57:08

看一下 Rcpp 包 - 我还没有机会亲自尝试,但它看起来像是从 R 调用 C++ 的好方法

http://dirk.eddelbuettel.com/code/rcpp.html - 或在 cran 上

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文