r - How to suppress error messages from a function?
问题描述
R> data.frame(x=1, y=1)
x y
1 1 1
R> suppressWarnings(rq(y~x, data=data.frame(x=1, y=1)[-1, , drop=F]))
Error in rq.fit.br(x, y, tau = tau, ...) : Singular design matrix
R> suppressMessages(rq(y~x, data=data.frame(x=1, y=1)[-1, , drop=F]))
Error in rq.fit.br(x, y, tau = tau, ...) : Singular design matrix
I want to suppress error messages above. But the two functions that I tried did not work. Is there a way to suppress error messages like this?
解决方案
try(...)
用using包装有问题的语句silent=TRUE
:
stop(TRUE)
## Error: TRUE
# this results in no displayed error message
try(stop(TRUE), silent = TRUE)
推荐阅读
- javascript - 无法访问 API 时 catch 不起作用
- python - 使用 feedparser 访问重复的提要标签
- javascript - JavaScript 地图归约函数
- javascript - 在 rxjs 中实现 startWith() 运算符时出现 TypeError
- html - 如何为 mat-grid-list 中的每个图块添加特定的下拉列表,我该怎么做?
- html - 在引导程序中添加到购物车项目布局
- list - 我们可以在 Cassandra 中使用集合类型(List、Set、Map)作为集群键吗?
- javascript - 如何使标签 i WCAG 2.0 在 wordpress 中兼容?
- javascript - 鼠标悬停在滑块上无法显示另一个图像
- c# - 用于将带有子选择的数据插入数据库的字符串