Reputation: 533
I want to save a part of my r script output including the commands into a text file. I know sink()
but it does not include the commands or I could not find a specific option to do that.
Is there any possibility to capture the commands and its ouput within an r session. Simply write an Rmd or capture the output within the console is not the solution at the moment.
Upvotes: 4
Views: 5071
Reputation: 44525
If you're working interactively, here's one idea. It was this specific problem for which I created the sinkstart()
function in the rite package. Basically, this creates a pop-up tcl/tk widget that you can write commands and output to. Here's a screenshot to give you a feel:
There are just two relevant functions: sinkstart()
starts the sink; sinkstop()
turns it off. You can toggle back and forth to selectively write to the widget. Then you can just save the contents with a right-click or a key shortcut.
Upvotes: 1
Reputation: 5105
You are probably looking for the TeachingDemos
package. Documentation can be found here.
Example:
library(TeachingDemos)
txtStart("test.txt")
# Your code
txtStop()
This should write both your command input and output to a file called test.txt
.
Upvotes: 7