This project is read-only.

Is it possible to call a user-defined (custom) R function from within C#?

Feb 9, 2013 at 3:01 PM
Edited Feb 9, 2013 at 3:02 PM
Hello

Is it possible to call a user-defined (custom) R function from within C#?

For example a matrix multiplication function written in R:

# c = a x b
matrix_mult = function(a, b) {
c = a %*% b;
return c;
}

How can I call this R function matrix_mult(a,b) from within c#?

Tunc
Feb 10, 2013 at 10:24 PM
This is no different from the examples given to the home page e.g. GenericVector testResult = engine.EagerEvaluate("t.test(group1, group2)").AsList();

provided you have loaded the definition of matrix_mult, you'd use

var myResult = engine.EagerEvaluate("matrix_mult(a, b)").AsNumericMatrix();
Feb 10, 2013 at 10:44 PM
The question was rather how to load the definition of the function matrix_mult(). After some research and trial I've found the answer:
http://stackoverflow.com/questions/14789417/is-it-possible-to-call-a-user-defined-custom-r-function-from-within-c

Thanks
Tunc