0
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?

user15502206
  • 121
  • 1
  • 3
  • 1
    Posts to SO should be reproducible by others. In particular all inputs and library statements should be shown. See the guidance at the top of the [tag:r] tag page. – G. Grothendieck Aug 16 '21 at 14:34
  • Maybe add `library(quantreg)` to be reproducible. – GKi Aug 16 '21 at 14:35
  • Have also a look at [Suppress error message in R](https://stackoverflow.com/q/19111956/10488504). – GKi Aug 16 '21 at 14:37

1 Answers1

5

Wrap the offending statement with try(...) using silent=TRUE:

stop(TRUE)
## Error: TRUE

# this results in no displayed error message
try(stop(TRUE), silent = TRUE)
G. Grothendieck
  • 254,981
  • 17
  • 203
  • 341