Print or capturing multiple objects in R

你说的曾经没有我的故事 提交于 2019-12-01 11:47:55

You can store the result as a list and then use the capture.output

fit1<-lm(mpg~cyl,data=mtcars)
fit2<-lm(mpg~cyl+disp,data=mtcars)
myresult<-list(fit1,fit2)
capture.output(myresult, file = "results.txt")

If you want multiple output sent to a file then look at the sink function, it will redirect all output to a file until you call sink again. The capture.output function actually uses sink.

You might also be interested in the txtStart function (and friends) in the TeachingDemos package which will also include the commands interspersed with the output and gives a few more options for output formatting.

Eventually you will probably want to investigate the knitr package for ways of running a set of commands in a batch and nicely capturing all the output together nicely formatted (and documented).

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!