[R] Appending diagnostic information to all lines sent to stdout and stderr

Thomas Allen hedbag at gmail.com
Thu Jun 19 08:47:01 CEST 2008


Dear All

I'm logging the stdout and stderr of an R program into two separate
files (stderr.txt and stdout.txt) using sink()
I would like to append extra information such as "date", "memory
usage" etc to every line of output that goes to stdout or stderr.

For example

> cat("hello \n")

should give output that looks something like:
"hello --- Thu Jun 19 18:39:15 2008 | cel_norm_expm | 389.6 Mb used |"
instead of just:
"hello"

I don't want to replace functions like "print", "cat", "stop" and
"warning" with my own special functions.
Instead, I want to somehow catch the messages that these functions
return and alter them before writing to my
logging files.
Any code that writes output by making calls to cat etc should be
completely isolated from the mechanism that is adding this extra
diagnostic information.

Is this actually possible?
I don't really like the idea of rewriting the "cat" function and
creating output for stdout from stderr using "kludges" like:

> options(error=function(x=geterrmessage()){cat(x)})

Thank you for any help and please ask me to explain my situation in
more detail if necessary

-- 
Thomas Allen
Department of Biochemistry
University of Otago
710 Cumberland street
Box 56
Dunedin
New Zealand
email1: hedbag at gmail.com
email2: allth025 at student.otago.ac.nz

Only the insane have strength enough to prosper and only those who
prosper can truly judge what is sane



More information about the R-help mailing list