user168574
user168574

Reputation: 15

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. I'm having problems getting data from R. Code is below

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

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

I get ParseException at this point. What can be the problem?

Thanks a lot.

Upvotes: 1

Views: 2367

Answers (1)

Ricardo
Ricardo

Reputation: 11

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.

Upvotes: 1

Related Questions