Skip to content
Prev 244500 / 398503 Next

How does Sweave write to a file?

On 09/12/2010 2:07 PM, Arnau Mir Torres wrote:
The problem is that Sweave executes each statement wrapped within sink( 
con ); statement; sink().  You need to avoid using sink() as a separate 
statement.  One way would be to put the lines

sink("foo.txt")
summary(lm(y~x))
sink()

into a block using braces {}; Sweave would wrap the whole function call, not the individual lines.  That's essentially what
capture.output() does, so this should work:

writeLines( capture.output( summary(lm(y~x)) ), "foo.txt")

You can probably do it in other ways too.

Duncan Murdoch