I'm having trouble calling my own R functions using R.Net; I have several user defined functions inside some R scripts myScript.R, ..., and I want to call this functions using R.net
this is what I've got so far
one myScript.R file contains several functions like this
userDefinedFunctionOne <- function(parameter1, parameter2)
{
.
.
.
}
userDefinedFunctionTwo <- function(parameter1, parameter2, ...)
.
.
.
and with R.Net, in the constructor of my class I create an instance of the REngine class
private REngine engine;
public MyClass()
{
this.engine = REngine.GetInstance();
}
then I source the myScript.R file
this.engine.Evaluate(@"source('C:/RScripts/myScript.R')");
but when I call my functions like this
var dataframe = this.engine.Evaluate(string.Format("dataframe <- userDefinedFunctionOne(parameter1 = {0}, parameter2 = {1})",
value1,
value2)).AsDataFrame();
I'm getting this error
Error: could not find function "userDefinedFunctionOne"
I've found seen some examples when the user functions is defined like this
Function data = engine.Evaluate(@"data <- function(a,b){
c = a %*% b;
return(c);
}").AsFunction();
but I want to avoid that, because as I wrote, I have several functions inside my R script files
is there a way to do this without rewriting my R functions as strings???
I would apreciate any help, thanks