2

I ma trying to use R language inside of C# application.

I have followed the instructions here - http://joachimvandenbogaert.wordpress.com/2009/03/26/r-and-c-on-windows/ and I can succesfully connect to R server via COM. But when I try to get the result of an operation I get null instead of a value:

connector.EvaluateNoReturn("x <- c(2,3,5,1,4,4)");
var result = connector.Evaluate("sum(x)"); // it is always null here

I wonder what else should I check? I've set compilation mode to X86 for my VS project/solution. I have pointed all Environment variables to i386 subfolder of bin folder, but nothing helps.

I have Win7 64bit, R version 2.15.0. Maybe I should try 64bit R instead?

Sergei
  • 1,617
  • 15
  • 31
  • I would rather suggest to use R 2.14 first. These COM interfaces are highly version-dependent, one of the reasons I gave up using these. – Dieter Menne Jun 01 '12 at 13:16
  • And what do you use now? Is there another solution to integrate C# and R? – Sergei Jun 01 '12 at 14:12
  • 1
    Well, there is http://rdotnet.codeplex.com/ which I tried to use. It is a great concept, but does not take off (see my part at http://rdotnet.codeplex.com/workitem/7), and is rarely updated. It's definitively not "stable" as it is marked. The community simply is too small. I am currently using RServe which is a mature product, even if it does not work so nicely together with c#; and Dirk Edelbüttel hates Windows anyway. – Dieter Menne Jun 01 '12 at 14:20
  • Thanks for pointing this out! I've installed Rserve from http://www.rforge.net/Rserve/index.html and I have found a C# client library for it here - http://www.koders.com/info.aspx?c=ProjectInfo&pid=8QU78AH4QGGA8EAGV81Y3S8P9B And it works like a charm :) – Sergei Jun 04 '12 at 07:05
  • Good to know; I had build my (much simpler) interface before that came up. Tried it later, but never got around the many "this project is not supported" when trying to start it, even if I have VS 2010 Professional. – Dieter Menne Jun 04 '12 at 09:42
  • Also note http://rservecli.codeplex.com/ – Dieter Menne Jun 04 '12 at 09:49
  • Yes, I also couldn't compile that project due to the same error message. I have just created a new Library project and added all files into it. And onl after that it compiled. – Sergei Jun 04 '12 at 13:26
  • Good to know. Because you asked, I revitalized my rservecli test project today, and it worked out of the box. From looking at the code quality, I would suggest that you use that one. – Dieter Menne Jun 04 '12 at 19:38

3 Answers3

3

Some shameless self-promotion: There's also RserveCLI, yet another library to access Rserve from .NET. I presented it last year at the R/Finance conference, and there seems to be a small user base.

0

Along the lines of Oliver's answer, you could try RserveCLI2 a fork of Oliver's project.

Suraj
  • 35,905
  • 47
  • 139
  • 250
0

There is another SO post you may want to check out, How can I access Windows COM objects in R v3?.

But really, shameless plug, R.NET has made some inroads since this original post and the comments of Dieter Menne, including on *nix platforms. Readers of this post needing .NET and R interop may want to give it a try.

Community
  • 1
  • 1
j-m
  • 1,473
  • 1
  • 13
  • 17