4

I am using R.NET library to call R functions in C#. I want to define or construct input in c# and pass it to the R command. I tried this :

engine.Evaluate("library(mirt)");
engine.Evaluate("x=mirt(Science,1)");
S4Object obj111 = engine.GetSymbol("x").AsS4();
engine.Evaluate("pl=x@Pl");
NumericVector pl_c= engine.GetSymbol("pl").AsNumeric();
int[] resp_c = new int  [] {1,1,1,1};
engine.Evaluate("ff=fscores(x, response.pattern=resp_c)");

While trying this I came across an error which says,

"resp_c" not found.

Is there any way to pass the input to R functions from C# without writing that input explicitly in double quotes which is nothing but only R script.

Thank very much for you response in advance.

Artiga
  • 776
  • 2
  • 16
  • 37

1 Answers1

3

Not an expert of c#, but a quick glance at the doc reveals that you can achieve what you want through:

int[] resp_c = new int  [] {1,1,1,1};
IntegerVector resp_cR = engine.CreateIntegerVector(resp_c);
engine.SetSymbol("resp_c", resp_cR);
engine.Evaluate("ff=fscores(x, response.pattern=resp_c)");

You need to create an R object out of your c# array and then give a symbol to it.

Honestly, I never programmed in c#, but I programmed in Java and in JRI (java/R integration) and have an idea as how to pass Java object to R. Can't test and cannot be sure if it will work, but maybe you can find this helpful in some way.

nicola
  • 24,005
  • 3
  • 35
  • 56