running complete scripts

Jun 22, 2011 at 11:35 PM

This maybe a stupid question, but can I run complete scripts from a file?

Somethign like this:

var rengine = RDotNet.REngine.CreateInstance("bla"); 
var xx = rengine.Evaluate(File.ReadAllText(scriptpath));

 If I do this I get an unknown application error as result of Evaluate()

 

Thanks

Jan


Jul 16, 2011 at 8:14 PM

I am also interested in finding out if this is possible as I have R codes spanning 500 lines and integrating them line by line is very difficult. So far I have used DCOM StatConnector but it has a lot of constraints so I'm looking for alternatives.

I started analyzing the source code for R.NET and I found out that the library is actually parsing the input string in Evaluate methods line by line.

More to come if somebody doesn't give us an answer.

Thanks

Jul 24, 2011 at 1:23 PM
Edited Jul 24, 2011 at 1:26 PM

I think if you use the commad "source" may be it will work for you, me I use it in this way

 

 

REngine R = REngine.GetInstanceFromID("RDotNet");
R.EagerEvaluate("source(\"MyRscript.r\")");

 

in this example the name of the file is MyRscript.r, here I used \" because normally in R it is written between two " ":

	source("MyRsccript.r")

To check if your script functions have been loaded you can try ls().

Hope it helps :).
Nb: Some times the R.net craches when you call function "source", but you can download the last version I think it had been solved.
Jul 24, 2011 at 5:31 PM
sirusbasevi wrote:

I think if you use the commad "source" may be it will work for you, me I use it in this way

 

 

REngine R = REngine.GetInstanceFromID("RDotNet");
R.EagerEvaluate("source(\"MyRscript.r\")");

 

in this example the name of the file is MyRscript.r, here I used \" because normally in R it is written between two " ":

	source("MyRsccript.r")

To check if your script functions have been loaded you can try ls().

Hope it helps :).
Nb: Some times the R.net craches when you call function "source", but you can download the last version I think it had been solved.

Thanks sirusbasevi,

This helps a lot! This solution requires an R source file to be available in the file system and there are some constraints but this solution is flexible (can change the R code without recompiling) and is enough for me.

 

Jun 28, 2012 at 7:29 AM

I want to pass arguments/parameters to the R script.

For example in command line I can call: Rscript.exe MyRscript.r C:\Test 2 where C:\Test is arg[1] and 2 is arg[2]

Ho can I do it from RDotNet?

My code: engine.EagerEvaluate("source(\"MyRscript.r\")");

Thanks for the help!

Adrian L