[R] Capture warnings

Gabor Grothendieck ggrothendieck at gmail.com
Tue Feb 19 19:58:11 CET 2008


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.
>
>



More information about the R-help mailing list