Thanks. This seems to mirror the output *both* to the console *and* to the
sink file. The error messages, on the other hand, show up only in the
console.

On Tue, Aug 4, 2009 at 3:24 PM, Allan Engelhardt <allane@cybaea.com> wrote:

> sink(..., type=c("output","message"), split=TRUE) at the beginning of your
> session should do it?
>
> Jacob Wegelin wrote:
>
>>
>> Consider all the text that one sees on the console during an R session.
>>
>> Is there a way, within R, to make all this text--both the "output" and the
>> "messages"--automatically get copied to a single text file, in addition to
>> seeing it on the console?
>>
>> If I remember to save the console to a file at the end of my R session,
>> that does it. But
>>
>> (1) That requires pointing and clicking--can it be automated as a text
>> command?
>>
>> (2) It would be nice to issue the text command at the start of the R
>> session, such as "log this entire session in mylog.txt, append", if this
>> would ensure that the session is logged whether I remember to save the
>> console or not.
>>
>> As far as I can tell,
>>
>> sink(file="mylog.txt")
>>
>> will hide the output from me and put it into mylog.txt. But it still shows
>> me the error messages.
>>
>> An attempt to put the output and messages into separate files returns an
>> error:
>>
>>  sink("junkout.txt", type="output")
>>> sink("junkmsg.txt", type="message")
>>>
>> Error in sink("junkmsg.txt", type = "message") :
>>  'file' must be NULL or an already open connection
>>
>> and at any rate I'd like both messages in the same file, just like on the
>> console.
>>
>> People who run R at the unix command line apparently use the unix command
>> -script-. But I mean something that will work within R,
>> platform-independent.
>>
>> A 2003 post to R-help suggests savehistory(), but this does *not* save the
>> console; I tried it just now. Another post from the same thread suggests
>> using emacs. But that is not platform-independent.
>>
>> The existence of the 2003 thread suggests that this issue comes up
>> periodically. Was it a deliberate design decision not to make logs
>> available, in contrast to the way logging works in Stata?
>>
>> I use the Rgui on a MacBook Pro:
>>
>>  sessionInfo()
>>>
>> R version 2.8.1 (2008-12-22) i386-apple-darwin8.11.1
>>
>> locale:
>> en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8
>>
>> attached base packages:
>> [1] stats     graphics  grDevices utils     datasets  methods   base
>>
>> other attached packages:
>> [1] lme4_0.999375-28   Matrix_0.999375-21 lattice_0.17-17
>> foreign_0.8-29
>>
>> loaded via a namespace (and not attached):
>> [1] boot_1.2-34 grid_2.8.1
>>
>>
>> Thanks for any insights.
>>
>> Jacob A. Wegelin
>> Assistant Professor
>> Department of Biostatistics
>> Virginia Commonwealth University
>> 730 East Broad Street Room 3006
>> P. O. Box 980032
>> Richmond VA 23298-0032
>> U.S.A. E-mail: jwegelin@vcu.edu URL: http://www.people.vcu.edu/~jwegelin
>>
>> ______________________________________________
>> R-help@r-project.org 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.
>>
>
> ______________________________________________
> R-help@r-project.org 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.
>

	[[alternative HTML version deleted]]


