Hi All, I would like to output the results of a function into a text file, legible as a such. The function produces a summary quite like: summary(lm(x ~ y + w * z)) [for instance] and I am not clear how to save this summary into a text file 'automagically', because I need to be able to do it in a for() loop. Cheers, Federico -- Federico C. F. Calboli Department of Epidemiology and Public Health Imperial College, St. Mary's Campus Norfolk Place, London W2 1PG Tel +44 (0)20 75941602 Fax +44 (0)20 75943193 f.calboli [.a.t] imperial.ac.uk f.calboli [.a.t] gmail.com
> I would like to output the results of a function into a text file, > legible as a such. The function produces a summary quite like: > > summary(lm(x ~ y + w * z))You can either redirect output to a file using cat or sink; generate a latex table using xtable (in the xtable package); or export the relevant bits (e.g. the coefficients matrix) using write.csv. Based upon your message, sink is probably your best bet/ sink(file="foo.txt") summary(lm(x ~ y + w * z)) sink(NULL) Regards, Richie. Mathematical Sciences Unit HSL ------------------------------------------------------------------------ ATTENTION: This message contains privileged and confidential inform...{{dropped:20}}
Would something like this do it? sink(file="reg.txt") summary(reg) sink() --- Federico Calboli <f.calboli at imperial.ac.uk> wrote:> Hi All, > > I would like to output the results of a function > into a text file, > legible as a such. The function produces a summary > quite like: > > summary(lm(x ~ y + w * z)) > > [for instance] > > and I am not clear how to save this summary into a > text file > 'automagically', because I need to be able to do it > in a for() loop. > > Cheers, > > Federico > > -- > Federico C. F. Calboli > Department of Epidemiology and Public Health > Imperial College, St. Mary's Campus > Norfolk Place, London W2 1PG > > Tel +44 (0)20 75941602 Fax +44 (0)20 75943193 > > f.calboli [.a.t] imperial.ac.uk > f.calboli [.a.t] gmail.com > > ______________________________________________ > R-help at r-project.org 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. >Looking for the perfect gift? Give the gift of Flickr! http://www.flickr.com/gift/
?capture.output On Nov 26, 2007 9:31 AM, Federico Calboli <f.calboli at imperial.ac.uk> wrote:> Hi All, > > I would like to output the results of a function into a text file, > legible as a such. The function produces a summary quite like: > > summary(lm(x ~ y + w * z)) > > [for instance] > > and I am not clear how to save this summary into a text file > 'automagically', because I need to be able to do it in a for() loop. > > Cheers, > > Federico > > -- > Federico C. F. Calboli > Department of Epidemiology and Public Health > Imperial College, St. Mary's Campus > Norfolk Place, London W2 1PG > > Tel +44 (0)20 75941602 Fax +44 (0)20 75943193 > > f.calboli [.a.t] imperial.ac.uk > f.calboli [.a.t] gmail.com > > ______________________________________________ > R-help at r-project.org 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve?
Federico Calboli <f.calboli at imperial.ac.uk> wrote:> > I would like to output the results of a function into a text file, > legible as a such. The function produces a summary quite like: >Take a look at the sink() function. Does that do what you need? -- Mike Prager, NOAA, Beaufort, NC * Opinions expressed are personal and not represented otherwise. * Any use of tradenames does not constitute a NOAA endorsement.