From gregory_r_warnes at groton.pfizer.com  Thu Oct  2 09:46:09 2003
From: gregory_r_warnes at groton.pfizer.com (gregory_r_warnes@groton.pfizer.com)
Date: Thu Oct  2 08:45:28 2003
Subject: [Rd] warnings() generates error if there never were any (PR#4389)
Message-ID: <200310020646.h926k90P008024@pubhealth.ku.dk>

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


[Rd] warnings() generates error if there never were any (PR#4389)
gregory_r_warnes@groton.pfizer.com