Re: [R] Command equivalent of rgui "File, Save to File"?

From: Duncan Murdoch <murdoch_at_stats.uwo.ca>
Date: Tue 12 Sep 2006 - 14:03:44 GMT

On 9/12/2006 9:27 AM, Michael Prager wrote:
> Duncan Murdoch wrote:
>

>> On 9/11/2006 3:57 PM, Michael Prager wrote:
>> > R 2.3.1 on Windows XP Professional.
>> > 
>> > I am writing some scripts to generate examples.  The Rgui menu
>> > item "File, Save to File" is helpful.  Is there perhaps an
>> > equivalent R function that can be incorporated into a script?
>> 
>> I think sink() is the closest you can get: set R to write to a file 
>> before generating whatever output you want to save.
>> 
>> The menu item writes out the GUI text buffer; the R core doesn't know 
>> what's in that buffer.  Other front ends don't have a buffer at all.
>> 

> [...]
>
> Thanks, Duncan, for the helpful response. Unless I have
> overlooked something (quite possible), sink() saves only the
> output, not the input as well. I'll continue using the menu
> system -- which I am delighted to have.
>

Another possibility is to put your script into a file (e.g. script.R), and run

Rcmd BATCH script.R

This puts the whole transcript of the session into script.Rout. It's not identical to running in the gui, because functions can tell whether they're running interactively or not, but it's close.

Duncan Murdoch



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Wed Sep 13 13:31:12 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 13 Sep 2006 - 04:30:07 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.