首页 > 解决方案 > 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?

标签: r

解决方案


try(...)用using包装有问题的语句silent=TRUE

stop(TRUE)
## Error: TRUE

# this results in no displayed error message
try(stop(TRUE), silent = TRUE)

推荐阅读