tags:

views:

419

answers:

2

How do you print to stderr in R?

This would especially useful for scripts written in Rscript.

A: 

Is it possible to configure the print function to print to stderr?

From Ripley himself:

No, but where standard output goes is controlled by sink(), so you can achieve the same effect. R internally has no idea what output comes from print() (which is not just one function but hundreds of methods).

Galwegian
+2  A: 

Actually the following works for me:

write("prints to stderr", stderr())

write("prints to stdout", stdout())
This is on Linux, with R 2.8.1 (using Rscript)
This code also works on Windows. For more formatting control, you can use cat instead of write.
Richie Cotton