[R] batch mode in linux

Thomas Lumley thomas at biostat.washington.edu
Thu Jul 27 22:19:40 CEST 2000



On Thu, 27 Jul 2000, John P. Burkett wrote:
> I'm trying to learn how to use R version 1.1.0 under Mandrake Linux
> version 6.1.  Using R interactively, I get good results.  However, when
> I attempt to execute commands from a file (following the directions in
> section 1.10 of An Introduction to R, version 1.10) my output
> disappears.

This should probably be added to the FAQ.

Short answer: 
	source(infile.R,echo=T) 
or 
	R BATCH infile.R outfile
or
	R --no-save <infile.R >outfile &


Long answer:
When code is run with source() there is only one way for information to
appear on the screen: it gets explicitly printed with print() or cat() or
a similar function.  If your file contains the line
	1+2
R will compute the value 3 but nothing will be printed because there is no
print() function. If it contains
	print(1+2)
then 3 will be printed.

In interactive mode, when you type in an expression, the value of that
expression is computed and then printed by the user interface If you type
	1+2
R will compute and return the value 3, and the user interface will print
it. If you type 
	print(1+2)
then the expression is evaluated (causing "3" to be printed) and then the
user interface prints the returned value of "print(1+2)", which is also 3,
so the output would appear twice.

The fact that source() doesn't normally print everything on the output is
a feature, not a bug.  The main use of source() is to load code. When you
type eg, library(nlme), literally hundreds of functions are read in. You
really don't want them appearing on the screen.


	-thomas

Thomas Lumley
Assistant Professor, Biostatistics
University of Washington, Seattle

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list