[R] executable R scripts

Jonathan Baron baron at psych.upenn.edu
Mon Jun 9 03:39:55 CEST 2003


On 06/08/03 17:35, John Zedlewski wrote:
>Hi, I'm a newbie trying to make an R program executable on UNIX, just like one 
>would write an executable perl script by putting "#!/usr/bin/perl" in the 
>first line, and so on.
>
>It seems, though, that this would only work if I use the "BATCH" command to 
>tell R to execute the program in its first argument. This would have the 
>unfortunately side-effect of dumping all output to a file rather than stdout.
>
>Additionally, I'd want to see only the results of "print" statements on 
>stdout, not all off R's output, just as when you source a script with 
>echo=FALSE.

See
man R
for how to do it, although I'm not sure where it says the
following:

To get just the print output and nothing else, it helps to have
print()'s in the script itself.  Then you can use

R --slave < myfile.R > printoutput.txt

I also use R --vanilla < myfile.R
for a R file that has write.table()'s in it.  For this you do not
need to pipe the output anywhere.




More information about the R-help mailing list