[R] Calling R in BATCH mode from C programm

alkatz@post.tau.ac.il alkatz at post.tau.ac.il
Tue May 20 17:29:41 CEST 2003

Hello R-people,

I have the following problem :

In order to run R script from DOS prompt in BATCH mode and pass it some
parameters I do the following :

Rterm --slave --no-save --no-restore <args.R> args.out ARG1=1 ARG2=2

It works fine :
the result is that the script args.R is isexecuted. Sys.getenv() sees the 
arguments ARG1 and ARG2, and the R creates output file args.out

Now I want to be able to call the same command from C application :

#include <conio.h>
#include <process.h>
#include <string.h>

void main()
   char *args[10], prog[80];
   int ch;

   strcpy(prog, "C:\\Program Files\\R\\RBase\\bin\\Rterm.exe "); 

   /* Arguments to Rterm.exe */
   args[0] = "--slave";
   args[1] = "--no-save";
   args[2] = "--no-restore";
   args[3] = "<args.R>";
   args[4] = "args.out";
   args[5] = "ARG1=1"; 
   args[6] = "ARG2=2";
   args[7] = NULL;

   _execl( prog, args[0], args[1], args[2], args[3], args[4], args[5], args[6], 

Rterm starts, but writes to output :

ARGUMENT '<args.R>' __ignored__
ARGUMENT 'args.out' __ignored__

Command Sys.getenv("ARG1") returns correct result => R sees the rest of the 

I tryed to type args[3] = "args.R" - without <> it does not help.

Does enyone know what might be my problem ??


More information about the R-help mailing list