python - 抑制 rpy2 中的警告

标签 python r warnings rpy2

当我使用 rpy2 在 python 中导入 R 时,我该如何抑制警告?

看来在 R 中你必须做以下事情

options(warn=-1)

...但我不熟悉 R。如何在 python 中执行此操作?

最佳答案

警告系统rpy2使用 Python 的 warnings模块。因此,您可以使用该软件包的 filterwarnings() 关闭警告。功能。正如此处对另一个答案的评论中已经指出的那样,这可能很危险,因为不仅与 R 相关的警告会受到影响。

但是,rpy2 带有自己的警告类 RRuntimeWarning。因此,您可以通过

import warnings
from rpy2.rinterface import RRuntimeWarning
warnings.filterwarnings("ignore", category=RRuntimeWarning)

关于python - 抑制 rpy2 中的警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11992138/

相关文章:

python - 安装 python 3.6 virtualenv 而不修改我的 python 3.5 安装

python - 为什么 Pandas 中的内存使用报告整数的数量与对象 dtype 的数量相同?

r - 安装 R 包 PearsonDS 会出现意外 token 错误

c++ - POD的默认析构函数是静态的吗?

mysql - Windows 日志中的可疑 MySQL 警告 : what's happening there?

python - 在 S3 上使用 boto 库

Python CGI 脚本 : Basic HTML Form With Two Submit Buttons

r - r : could not find function "FUN" 中的 by() 错误

r - R中不同范围/尺度的连续异质变量的层次聚类

visual-studio-2010 - 更改输出文件设置时警告 MSB8012