
William, The function keepWarnings that you wrote did the trick. Thanks for the help!

 

                  Aaron
 
> Subject: Re: [R] deleting/removing previous warning message in loop
> Date: Fri, 27 Mar 2009 13:33:51 -0700
> From: wdunlap@tibco.com
> To: awells10@hotmail.com
> 
> You try a using function like the following (based
> on suppressWarnings):
> keepWarnings <- function(expr) {
> localWarnings <- list()
> value <- withCallingHandlers(expr,
> warning = function(w) {
> localWarnings[[length(localWarnings)+1]] <<- w
> invokeRestart("muffleWarning")
> })
> list(value=value, warnings=localWarnings)
> }
> It returns a 2-element list, the first being the value
> of the expression given to it and the second being a
> list of all the warnings. Your code can look through
> the list of warnings and decide which to omit. E.g.,
> 
> > d<-data.frame(x=1:10, y=rep(c(FALSE,TRUE),c(4,6)))
> > z <- keepWarnings(glm(y~x, data=d, family=binomial))
> > z$value
> 
> Call: glm(formula = y ~ x, family = binomial, data = d)
> 
> Coefficients:
> (Intercept) x
> -200.37 44.52
> 
> Degrees of Freedom: 9 Total (i.e. Null); 8 Residual
> Null Deviance: 13.46
> Residual Deviance: 8.604e-10 AIC: 4
> > z$warnings
> [[1]]
> <simpleWarning in glm.fit(x = X, y = Y, weights = weights, start =
> start, etastart = etastart, mustart = mustart, offset = offset,
> family = family, control = control, intercept = attr(mt,
> "intercept") > 0): algorithm did not converge>
> 
> [[2]]
> <simpleWarning in glm.fit(x = X, y = Y, weights = weights, start =
> start, etastart = etastart, mustart = mustart, offset = offset,
> family = family, control = control, intercept = attr(mt,
> "intercept") > 0): fitted probabilities numerically 0 or 1 occurred>
> 
> > str(z$warnings[[1]])
> List of 2
> $ message: chr "algorithm did not converge"
> $ call : language glm.fit(x = X, y = Y, weights = weights, start =
> start, etastart = etastart, mustart = mustart, offset = offset,
> family = family, control = control, ...
> - attr(*, "class")= chr [1:3] "simpleWarning" "warning" "condition"
> > sapply(z$warnings, function(w)w$message)
> [1] "algorithm did not converge"
> [2] "fitted probabilities numerically 0 or 1 occurred"
> 
> You can filter out the ones you don't want to hear about
> and recall warning() with the interesting ones or present
> them in some other way.
> 
> 
> Bill Dunlap
> TIBCO Software Inc - Spotfire Division
> wdunlap tibco.com 
> 
> -------------------------------
> I am having difficulty deleting the last warning message in a loop so
> that the only warning that is produced is that from the most recent line
> of code. I have tried options(warn=1), rm(last.warning), and resetting
> the last.warning using something like: ...

_________________________________________________________________
[[elided Hotmail spam]]
plorer 8.

[[elided Hotmail spam]]
	[[alternative HTML version deleted]]


