[R] Several simple but hard tasks to do with R
Thomas Lumley
tlumley at u.washington.edu
Thu Aug 20 18:01:58 CEST 2009
On Thu, 20 Aug 2009, Ottorino-Luca Pantani wrote:
> Rakknar ha scritto:
>> 1. Make a log. I've been using Stata and there i have a great tool to
>> register what the program do: the log file, wich it's a simple .txt file
>> where Stata writes every output it makes (not graphics of course). When I
>> wanted to make the same thing with R I started to use the function sink()
>> but it only register the results of the commands (summaries for example) and
>> not the commands itself, witch it's really uncomfortable because it's harder
>> to find out to witch command that results come from.
>>
>>
> A possible workaround could be:
>
> sink("ouputfile.txt")
> as.character("rnorm(5, mean = 0, sd = 1)")
> rnorm(5, mean = 0, sd = 1)
> sink()
>
> I know, it is not elegant, and a bit repetitive, but it could help.
This is why sink() has the split=TRUE option, which logs output to a connection and sends it to the screen.
The R
sink("analysis.log",split=TRUE)
is almost identical to the Stata
log using analysis.log
with sink() to close the log and flush to disk at the end of the session.
-thomas
Thomas Lumley Assoc. Professor, Biostatistics
tlumley at u.washington.edu University of Washington, Seattle
More information about the R-help
mailing list