简体   繁体   English

R.NET从R获取数据

[英]R.NET Getting Data from R

I'm trying to make a simple statistical tool with using R and R.NET on C#.NET environment. 我正在尝试在C#.NET环境中使用R和R.NET来制作一个简单的统计工具。 I'm having problems getting data from R. Code is below 我在从R获取数据时遇到问题。代码如下

bool initResult = REngine.SetDllDirectory(rPackagePath);

if (!initResult)
   throw new Exception(@"R Initialization Failed");

engine = REngine.CreateInstance("tsEngine");

if (engine == null)
   throw new Exception(@"REngine Creation Failed");

engine.Evaluate("testData<-read.table('test_data.txt',sep='', header=TRUE)");

I'm trying to get the imported data and show it in a gridview 我正在尝试获取导入的数据并将其显示在gridview中

DataFrame dataset = engine.EagerEvaluate("testData").AsDataFrame();

I get ParseException at this point. 我现在得到ParseException。 What can be the problem? 可能是什么问题?

Thanks a lot. 非常感谢。

First, change the last line to: 首先,将最后一行更改为:

DataFrame testData = engine.Evaluate("testData<-read.table('test_data.txt',sep='', header=TRUE)").AsDataFrame();

Then add the following line: 然后添加以下行:

engine.SetSymbol("testData",testData);

With the SetSymbol your engine will recognize the variable "testData" if you use it again. 如果使用SetSymbol,您的引擎将再次识别变量“ testData”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM