I see a rich set of graphic device functions to redirect that output. Are there commands to redirect text as well. I have a set of functions that execute many linear regression tests serially and I want to capture this in a file for printing. Thanks, Stan Hopkins [[alternative HTML version deleted]]
Stan Hopkins wrote:> > I see a rich set of graphic device functions to redirect that output. Are > there commands to redirect text as well. I have a set of functions that > execute many linear regression tests serially and I want to capture this > in a file for printing. > > Thanks, > > Stan Hopkins >Yes, there are. ?sink You could also run your functions from a batch mode: R < your_script.R > output.txt or Rscript your_script.R > output.txt This, however, will give you a single file, while sink() allows creation of multiple files. capture.output can store the output in an array of character strings. -- View this message in context: http://www.nabble.com/Redirecting-print-output-tf4134131.html#a11758652 Sent from the R help mailing list archive at Nabble.com.
Here are two simple ways: === method1 ==cat("line1","\n",file="output.txt") cat("line2","\n",file="output.txt",append=TRUE) === method2 ==sink("output.txt") cat("line1","\n") cat("line2","\n") out <- lm(y~x,data=data.frame(x=1:10,y=(1:10+rnorm(10,0,0.1)))) print(out) sink() And then there is 'Sweave'. Check out, for instance <http://www.stat.umn.edu/~charlie/Sweave/> You can embed R code, figures, and output from print methods into your latex document. ST --- Stan Hopkins <stanhopkins at comcast.net> wrote:> I see a rich set of graphic device functions to redirect that output. Are > there commands to redirect text as well. I have a set of functions that > execute many linear regression tests serially and I want to capture this in > a file for printing. > > Thanks, > > Stan Hopkins > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >____________________________________________________________________________________Ready for the edge of your seat? Check out tonight's top picks on Yahoo! TV.
You may want to look at the R2HTML package as one approach (others have already told you about sink and cat). Another approach is to use the variations on sweave. Here you set up a template file with the code you want run as well as any explanitory text (you can even write an entire report), then process this with sweave and the output will be included. The original sweave works with LaTeX, there is an HTML driver for sweave in the R2HTML package (so the source and final documents are html) and there is an odfWeave package that lets you create the template and output in a word processor (uses the openoffice word processor, but since you can convert from and to Msword from there, this is not much of a limitation). Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at intermountainmail.org (801) 408-8111> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Stan Hopkins > Sent: Monday, July 23, 2007 9:35 PM > To: R help > Subject: [R] Redirecting print output > > I see a rich set of graphic device functions to redirect that > output. Are there commands to redirect text as well. I have > a set of functions that execute many linear regression tests > serially and I want to capture this in a file for printing. > > Thanks, > > Stan Hopkins > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
Reasonably Related Threads
- Extracting lists in the dataframe $ format
- data.frame loses name when constructed with one column
- Is there a way to edit a specific line in a function (e.g: doing function->text->edit->function) ?
- YAML inconsistencies...
- expression() - Superscript in y-axis, keeping line break in string