tags:

views:

101

answers:

1

How do you sink both the console input and the console output to a text file? Take the following code:

sink("temp.txt")
1:10
sink()

It will write a text file that looks like this:

[1]  1  2  3  4  5  6  7  8  9 10

But how do I create a text file that looks like this:

>   1:10
 [1]  1  2  3  4  5  6  7  8  9 10

I've looked at ?sink and searched R-help. I've also read: http://stackoverflow.com/questions/1343442/maintaining-an-input-output-log-in-r

If it makes a difference, I'm using StatET and Eclipse.

+5  A: 
library(TeachingDemos)

txtStart("temp.txt")
1:10
txtStop()

The text file now looks like

> 1:10
 [1]  1  2  3  4  5  6  7  8  9 10
gd047
Thanks. It seems to work well. I'm surprised that a similar function is not a part of Base R.
Jeromy Anglim