Suppress C warning messages in R

后端 未结 1 1370
故里飘歌
故里飘歌 2020-12-11 05:44

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 k

1条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-11 06:30

    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).

    0 讨论(0)
提交回复
热议问题