将DataTable通过COM传递到R中 [英] Passing DataTable over COM into R

查看:157
本文介绍了将DataTable通过COM传递到R中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图传递数据从SQL,到C#,然后到R服务器进行数据分析,然后回到我的Web应用程序;但是,我使用的COM接口不允许复杂的数据类型在C#和R(无数据表)之间传递。我已经通过使用下面的代码工作:

I am trying to pass data from SQL, to C#, then to an R server for data analysis then back to my web application; however, the COM interface that I am using does not allow complex data types to be passed between C# and R (no data tables). I have gotten it to work in the past by using the following code:

    int count = dataTable.Rows.Count;
    object[] y = new object[count];
    object[] x = new object[count];

    //R does not accept DataTables, so here we extract the data from
    //the table and pass it into 2 double arrays.
    for (int i = 0; i < count; i++)
    {
        y[i] = Convert.ToDouble(dataTable.Rows[i][0]);
        x[i] = Convert.ToDouble(dataTable.Rows[i][1]);
    }
    //Instantiate R connection
    StatConnector r = new STATCONNECTORSRVLib.StatConnectorClass();
    r.Init("R");
    r.SetSymbol("y", y);  //Passes column y into R
    r.SetSymbol("x", x);  //Passes column x into R

我的问题现在出现了,因为我不再限于只是双打,从SQL数据库出来的任何东西都是公平的游戏(int,varchar,etc ...),我不再只调用2列数据(它可以是用户指定的许多)。

My problem now arises because I am no longer limited to just doubles, anything coming out of the SQL Database is fair game (int, varchar, etc...), and that I am no longer calling just 2 columns of data (it can be however many the user specifies).

如何将动态大小和动态数据类型的数据类型转换为可以安全传递到rcom的数组?

How can I convert a datatable of dynamic size and dynamic data types into an array that would be safe to pass over into rcom?

推荐答案

在Rockford Lhotka的专业Visual Basic 6.0业务对象中( http://search.barnesandnoble.com/Professional-Visual-Basic-Basic-Business-Objects/Rockford-Lhotka/e/9781861001078 ),他做了各种语句,跨应用程序边界的COM接口之间最有效的数据传输结构是String。我不知道这是否真的,但我接受他的资格。因此,我相信Biff MaGriff的建议是一个很好的简单实现你的问题。

In Professional Visual Basic 6.0 Business Objects by Rockford Lhotka (http://search.barnesandnoble.com/Professional-Visual-Basic-60-Business-Objects/Rockford-Lhotka/e/9781861001078), he makes various statements that the most effective data transfer structure between COM Interfaces across application boundaries is the String. I do not know if this is true, but I accept his qualifications. Therefore, I believe Biff MaGriff suggestion would be the a good simple implementation to your problem.

这篇关于将DataTable通过COM传递到R中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆