[R] runing .r file from C#

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Aug 21 15:17:27 CEST 2007

On Tue, 21 Aug 2007, Alex MD wrote:

> Hi,
> I know that the general subject "calling R from C" has been discused but I
> have been reading the manuals and also scouting the lists and I can not seam
> to find
> a working solution for my problem.

It's a C# issue.

>  I want to call a R script ( let's call it "test.r" ) from within C# code.
>  After reading about this topic I am trying to do this :
> System.Diagnostics.Process proc = new System.Diagnostics.Process();
> proc.StartInfo.FileName = "E:/R/R-2.5.1 /bin/Rterm.exe";
> proc.StartInfo.Arguments = " <'test.r' --no-save";
> proc.StartInfo.UseShellExecute = false;
> proc.StartInfo.RedirectStandardOutput = false;
> proc.Start();
> bun when Rterm starts it shows parameter <test.r ignored
> When I try to do the same from a command line shell it DOES work just fine :
> " Rterm.exe <test.r --no-save"  runs the file without any problems.
> Do you have any idea how to make it not to ignore the input file? Or is
> there other way to just execute a .r file from C# code?

You need a shell for redirection (< > |) to work, and 'system' commands in 
Windows do not usually use one (as in C, C++, R, Perl): you seem to have 
turned off using a shell in C#.  However, I think you should be using 
RScript.exe, where this is not an issue.

Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

More information about the R-help mailing list