R中燮preSS C警告讯息 [英] Suppress C warning messages in R
问题描述
我打电话从中接口与LIBSVM(一个C程序)第r包e1071的R功能。此功能是通过C(的printf)警告消息到R控制台。我知道这是因为警告消息的形式是(警告:...),而R警告消息是资本(即警告:...)。
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:...).
我试过一切R中摆脱这些消息(水槽,SUP pressWarnings,无形的),但似乎没有任何工作。
I've tried everything to get rid of these messages in R (sink, suppressWarnings, invisible) but nothing seems to work.
任何想法?
谢谢!
推荐答案
该函数使用的 STDIO 的而不是 Rprintf
/ REprintf
或警告
这就是为什么r输出的重新定向将不起作用。正确的解决方法是修复 LIBSVM
呼叫使用右输出来代替。
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.
黑客入侵的 STDIO 的输出是可能的 - 你可以重新直接输出到自己的管道,做你想做的事情是什么,但)它是一个在C位的工作和b)是危险的,因为你需要恢复标准的行为,你正在使用的功能完成后 - 如果在使用的外壳,即使出现了错误以及c)可与R输出交互
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.
如果你想有一个真正的怪诞,但脏快速解决方案,请在您收集功能(并行(...,沉默= TRUE))[[1]]
从多核
- 它燮presses 标准输出的(你可以添加多核::: closeStderr()
,如果你想用晚餐preSS的标准错误的为好)。
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).
这篇关于R中燮preSS C警告讯息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!