[R] printing output to a file from the command line

Marc Schwartz (via MN) mschwartz at mn.rr.com
Thu Apr 13 22:29:22 CEST 2006


On Thu, 2006-04-13 at 15:11 -0500, Chad Reyhan Bhatti wrote:
> Hello,
> 
> I have been looking for a way to print output to a file from the command
> line.  I have looked at write(), dump(), dput(), etc and none of these
> seem to have the capability I am needing.  Imagine that you have the
> output of lm(), glm(), or optim().
> 
> out <- lm();
> out <- glm();
> out <- optim();
> 
> I would like to be able to write(out, file="out.txt",replace=TRUE),
> write2file(out,file="out.txt",replace=TRUE) or
> print(out, file=out.txt",replace=TRUE).  I have several outputs to be
> printed so I
> would prefer it if I could write them to file from the command line as
> opposed to pasting them by hand.
> 
> Thanks,
> 
> Chad R. Bhatti

See ?sink and ?capture.output

HTH,

Marc Schwartz




More information about the R-help mailing list