[Rd] warnings() generates error if there never were any (PR#4389)

gregory_r_warnes at groton.pfizer.com gregory_r_warnes at groton.pfizer.com
Thu Oct 2 09:46:09 MEST 2003


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



More information about the R-devel mailing list