Re: [R] Capture warnings

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Tue, 19 Feb 2008 13:58:11 -0500

Check out:

https://stat.ethz.ch/pipermail/r-help/2006-March/101812.html

On Feb 19, 2008 1:41 PM, Nitin Jain <nitin.jain_at_bms.com> wrote:
> Dear R-help members,
>
> I am using logistic regression on a high throughput data and would like
> to capture warning messages, if generated for a particular probe. The
> way I am approaching it currently is:
>
> myResult <- data.frame(matrix(NA, nrow = 1000, ncol = 4))
> colnames(myResult) <- c("intercept", "coef", "SE", "Warnings")
> myResult[, "Warnings"] <- "" ## initially set each warning as blank
>
> for (i in seq(nrow(myResult))) {
>
> options(warn = 2) ## Convert warnings to error
> probeData <- origData[i, ] ## get current probe data
>
> fit1 <- try(glm(y ~ x, probeData)) ## fit logistic regression
>
> if (inherits(fit1, "try-error")) { ## change the warn option to 0 and refit
> options(warn = 0)
> fit1 <- try(glm(y ~ x, probeData))
> myResult[i, "Warnings"] <- names(last.warning)[1]
> }
>
> ## Fill in the other columns of myResult
> ...
> }
>
>
> When I run the above code in batch mode, I get the error:
> Error in x[[jj]][iseq] <- vjj : incompatible types (from NULL to
> character) in subassignment type fix
>
> I think the error is due to the fact that when the first warning message
> is generated, last.warning still does not exist in the function (but in
> some other environment), hence R is trying to assign NULL to a character.
>
> Can anyone tell me how to fix the above problem?
>
> Thanks.
>
> Best,
> Nitin
>
>
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Tue 19 Feb 2008 - 19:00:25 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 19 Feb 2008 - 19:30:15 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive