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

From: Thomas Allen <hedbag_at_gmail.com>
Date: Thu, 19 Jun 2008 18:47:01 +1200


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

______________________________________________
R-help_at_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.
Received on Thu 19 Jun 2008 - 07:47:14 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 19 Jun 2008 - 08:31:18 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.

list of date sections of archive