Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you sink input and output to a text file in R?

Tags:

r

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: maintaining an input / output log in R

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

like image 713
Jeromy Anglim Avatar asked Jun 06 '10 07:06

Jeromy Anglim


People also ask

How do I copy R console output?

How can I copy the output of the R console into a word document? Select what you want in the console and copy. Then in Word paste using Keep Text Only. (Right click to get the paste options.)

How do I save an R output to a text file?

You can also save the entire R console screen within the GUI by clicking on "Save to File..." under the menu "File." This saves the commands and the output to a text file, exactly as you see them on the screen.

How do you save a console output to a text file in R studio?

Click on the Console window, go to the File menu and select “Save Workspace...”. In another R session, you open this workspace with the “Load Workspace...” command. To save everything that has scrolled past on the Console window, click on the Console window. Go to the File menu, and then select “Save to File...”.


1 Answers

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
like image 130
George Dontas Avatar answered Sep 28 '22 12:09

George Dontas