[R] Capture warnings

From: Nitin Jain <nitin.jain_at_bms.com>
Date: Tue, 19 Feb 2008 13:41:01 -0500

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?



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 - 18:48:50 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