This project is read-only.

Execute local R script

Aug 20, 2013 at 6:38 AM
I'm looking to use R.NET to execute an existing R script but haven't had success. Is this actually possible? I've run the example code successfully, so my basic setup is ok.

My code looks like the following:
      static void RTest()
      {
         var envPath = Environment.GetEnvironmentVariable("PATH");
         var rBinPath = System.Environment.Is64BitProcess ? @"C:\Program Files\R\R-3.0.1\bin\x64" : @"C:\Program Files\R\R-3.0.1\bin\i386";
         Environment.SetEnvironmentVariable("PATH", envPath + Path.PathSeparator + rBinPath);

         using( var engine = REngine.CreateInstance("RDotNet") )
         {
            engine.Initialize();

            using( var fs = File.OpenRead(@"C:\R-scripts\r-test.R") )
            {
               engine.Evaluate(fs);
            }
         }
      }
Which I'm running in a console app for testing (eventually I want to have it run server-side in a web app).

The r-test.R script works when run in RStudio so there's no problem there and should result in writing a csv file to disk. I do see some 'Loading required package' messages being output to the console so something is working but the resultant csv file does not appear.
Aug 29, 2013 at 10:33 AM
Hi

No need for you to read the file in C#
Try it this way:
engine.Evaluate("source(\"C:\\R-scripts\\r-test.R\")");
Sep 6, 2013 at 1:55 AM
For readers of this discussion, see also http://stackoverflow.com/a/18648206/2752565.
May 28, 2015 at 7:35 AM
How to pass dataset or datatable to R script