[R] sink() and command files

Thomas Lumley tlumley at u.washington.edu
Tue Mar 13 17:16:55 CET 2001


On Tue, 13 Mar 2001, Malerba Giovanni wrote:

> Dear all,
> if I type from the R command line the following:
>
> ped <- read.table("R.ped", header=TRUE, sep=";",na.strings="x")
> p <- glm(formula=Dust.mites ~ Graminacee+IgE.num+geneA,ped,family=binomial(logit))
> sink (file="r.output")
> summary(p)
> sink()
>
> everything works fine and 'r.output' is generated.
> BUT , if I write (with an editor) the same lines into a command-file (i.e.
> r.bat)  and from the R command line I type: source("r.bat")
> the r.output is generated but it is empty.
> What should I do to write a command-file that is able to re-direct the R
> output to a file?

That isn't the problem.  You need to write a command file that generates
some R output.

The command
	summary(p)
does not generate any output. It computes a set of summaries and returns
them in an R object of class "summary.glm".

If you type "summary(p)" at the command line the returned value is
automatically printed, but in other circumstances it isn't.

To print the value use
	print(summary(p))
instead.

This should be added to the FAQ; it confuses a lot of people.

	-thomas

Thomas Lumley			Asst. Professor, Biostatistics
tlumley at u.washington.edu	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