Suppress C warning messages in R

I call the R function from package R1010, which is paired with libsvm (C program). This function sends C warning messages (printf) to the R console. I know this because the warning messages have the form (warning: ...), while the R warning messages are in the header (i.e. Warning: ...).

I tried everything to get rid of these messages in R (shell, suppressWarnings, invisible), but nothing works.

Any ideas?

Thanks!

+6
source share
1 answer

The function uses stdio instead of Rprintf / REprintf or warning , so redirecting the output R will not work. The correct solution is to fix the calls in libsvm to use the output R.

Stdio output may fail - you can redirect the output to your own channel and do what you want with it, but a) it works a little in C and b) it is dangerous because you need to restore the standard behavior after you finish with the function - even if it is an error and c) internally it can interact with the output R, if used in the shell.

If you want a really good, dirty, but 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).

+9
source

Source: https://habr.com/ru/post/905868/


All Articles