gregory_r_warnes@groton.pfizer.com
2003-Oct-02 08:45 UTC
[Rd] warnings() generates error if there never were any (PR#4389)
This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------_=_NextPart_000_01C388B0.D441A780 Content-Type: text/plain; charset="iso-8859-1" In debugging a long-running function where I occasionally call warnings() to write out any warnings that have occurred, I discovered that calling warnings() before any warnings have ever been generated causes an error:> warnings()Error in warnings() : Object "last.warning" not found The problem is that warnings() attemts to check the length of the variable 'last.warning' without first checking for its existance. This problem exists in R 1.7.1 as well as in the new 1.8.0 beta code. A simple patch fixes the problem: --- warnings.R.orig 2003-10-02 02:35:04.359451000 -0400 +++ warnings.R 2003-10-02 02:42:08.900717000 -0400 @@ -1,6 +1,6 @@ warnings <- function(...) { - if(!(n <- length(last.warning))) + if(!exists("last.warning") || !(n <- length(last.warning))) return() names <- names(last.warning) cat("Warning message", if(n > 1)"s", ":\n", sep="") -Greg LEGAL NOTICE\ Unless expressly stated otherwise, this messag...{{dropped}}
maechler@stat.math.ethz.ch
2003-Oct-02 09:54 UTC
[Rd] warnings() generates error if there never were any (PR#4389)
>>>>> "Greg" == gregory r warnes <gregory_r_warnes@groton.pfizer.com> >>>>> on Thu, 2 Oct 2003 08:46:09 +0200 (MET DST) writes:Greg> This message is in MIME format. Since your mail reader does not understand Greg> this format, some or all of this message may not be legible. Greg> ------_=_NextPart_000_01C388B0.D441A780 Greg> Content-Type: text/plain; charset="iso-8859-1" [ please *never* attach anything for bug reports. The current bug-management system messes up the MIME ] Greg> In debugging a long-running function where I Greg> occasionally call warnings() to write out any warnings Greg> that have occurred, I discovered that calling Greg> warnings() before any warnings have ever been Greg> generated causes an error: >> warnings() Greg> Error in warnings() : Object "last.warning" not found Greg> The problem is that warnings() attemts to check the Greg> length of the variable 'last.warning' without first Greg> checking for its existance. Greg> This problem exists in R 1.7.1 as well as in the new 1.8.0 beta code. Greg> A simple patch fixes the problem: Greg> --- warnings.R.orig 2003-10-02 02:35:04.359451000 -0400 Greg> +++ warnings.R 2003-10-02 02:42:08.900717000 -0400 Greg> @@ -1,6 +1,6 @@ Greg> warnings <- function(...) Greg> { Greg> - if(!(n <- length(last.warning))) Greg> + if(!exists("last.warning") || !(n <- length(last.warning))) Greg> return() Greg> names <- names(last.warning) Greg> cat("Warning message", if(n > 1)"s", ":\n", sep="") Thank you Greg! Fortunately, this falls into the category of "trivial bug fix" (it cannot break anything), and hence still goes into 1.8.0 Martin Maechler <maechler@stat.math.ethz.ch> http://stat.ethz.ch/~maechler/ Seminar fuer Statistik, ETH-Zentrum LEO C16 Leonhardstr. 27 ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND phone: x-41-1-632-3408 fax: ...-1228 <><