7

I am calling an R function from the R package e1071 which is interfaced with libsvm (a C program). This function is passing C (printf) warning messages to the R console. I know this because the warning messages are of the form (warning:...) whereas R warning messages are capitalized (i.e. Warning:...).

I've tried everything to get rid of these messages in R (sink, suppressWarnings, invisible) but nothing seems to work.

Any ideas?

Thanks!

Michael
  • 7,087
  • 21
  • 52
  • 81
  • Why so vague? Are you interfacing to libsvm via an R package? Or are you working on something custom? GCC is a compiler, I doubt run-time warnings are coming from it, more likely they are printfs in the libsvm C code. – Mark Jan 12 '12 at 21:32
  • yep e1071 package - I think you're right, the messages are coming from a printf statement. Do I need to go into the C code and delete it? or is there something I can do from R? – Michael Jan 12 '12 at 21:35
  • also I don't remember ever installing libsvm on my machine, I just downloaded the R package. Does that mean the libsvm source code is in the R package? – Michael Jan 12 '12 at 21:37
  • I think this is related to [your recent question](http://stackoverflow.com/questions/8842024/suppressing-warning-messages-in-e1071-in-r), and [your other recent question](http://stackoverflow.com/questions/8842301/suppressing-warning-messages-in-e1071-in-r). Try and keep them all in the same place. – nograpes Jan 12 '12 at 21:48
  • In case it helps, the code printing the messages is in the file `src/svm.cpp` in the `e1071` package sources. – Josh O'Brien Jan 12 '12 at 21:49

1 Answers1

11

The function uses stdio instead of Rprintf/REprintf or warning which is why re-direction of the R output won't work. The proper solution is to fix the calls in libsvm to use R output instead.

Hacking the stdio output is possible - you can re-direct the output to your own pipe and do what you want with it, but a) it's a bit of work in C and b) it's dangerous because you need to restore the standard behavior after you're done with the function - even if it errors out and c) in may interact with R output if used on a shell.

If you want a really whacky, dirty yet quick solution, run your function in collect(parallel(..., silent=TRUE))[[1]] from multicore - it suppresses stdout (you can add multicore:::closeStderr() if you want to suppress stderr as well).

Simon Urbanek
  • 13,842
  • 45
  • 45