How do you type on stderr in R?

How do you type stderr in R ?

This is especially useful for scripts written in Rscript .

+48
r printing stderr
Jul 10 '09 at 11:25
source share
3 answers

Actually the following works for me:

 write("prints to stderr", stderr()) write("prints to stdout", stdout()) 
+52
Jul 10 '09 at 12:21
source share

Here's a more flexible version for debugging / reusability in Rscript. It not only prints to stderr at your request, but also allows you to pass a variable number of arguments, types, etc., For example printf .

 v <- function(...) cat(sprintf(...), sep='', file=stderr()) 

Now you can do things like:

 v("name: %s age: %d\n", name, age) 

and etc.

+12
Dec 18 '14 at 20:43
source share

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

From Ripley himself :

No, but where there is standard output controlled by a shell (), so you can achieve the same effect. R internally has no idea what print () result is (which is not only one but hundreds of methods).

+7
Jul 10 '09 at 11:30
source share



All Articles