Skip to content

turning off specific types of warnings

3 messages · Eleni Rapsomaniki, jim holtman, Romain Francois

#
Dear R users,

I have a long function that among other things uses the "survest" function from the Design package. This function generates the warning:

In survest.cph (...)
  S.E. and confidence intervals are approximate except at predictor means.
Use cph(...,x=T,y=T) (and don't use linear.predictors=) for better estimates.

I would like to turn this specific warning off, as it makes it difficult to detect other (potentially more crucial) warnings generated by other parts of my code.

Is there a way to do this?

Eleni Rapsomaniki

Research Associate
Strangeways Research Laboratory
Department of Public Health and Primary Care

University of Cambridge
?
#
jim holtman wrote:
Note that this removes __all__ warnings, if you only want to remove 
specific warnings, you can adapt suppressWarnings like this:

 > h <- function(w) if( any(grepl("ouch", w))) 
invokeRestart("muffleWarning")
 > withCallingHandlers( warning("ouch"), warning = h )
 > withCallingHandlers( warning("something else"), warning = h )
Warning message:
In withCallingHandlers(warning("something else"), warning = h) :
  something else

Maybe it would make sense to extend suppressWarnings in this direction

Romain