From leif at reflectivity.com  Thu Mar 30 19:59:54 2006
From: leif at reflectivity.com (Leif Kirschenbaum)
Date: Thu, 30 Mar 2006 09:59:54 -0800
Subject: [Rd] request to add "..." to cat(ngettext in "warnings" function
Message-ID: <200603301759.k2UHxviY009706@hypatia.math.ethz.ch>

Madams & Sirs,
  I am working on porting some R code to one of our servers to run under web or crontab direction.  With that in mind I have been working on directing informative, warning, and error messages to outputs as I require.  I would like to suggest a change to the "warnings" function; that the passed arguments be enabled to all instances of "cat" in the function, specifically that the "cat(ngettext" have the ellipsis added to the call so that users may be able to call warnings as "warnings(file=stderr())" and the function will write all text to the stderr stream.  As it is written today, the text "Warning message:" is written to the console output no matter what.  Since I am writing only output to the console output which is to be passed to the calling script (PHP, shell script, etc.) I need to divert all other messages to the stderr which I log using sink, so I need all of warnings' output to go to stderr.

Thank you.


warnings<-function (...) 
{
    if (!exists("last.warning", envir = .GlobalEnv)) 
        return()
    last.warning <- get("last.warning", envir = .GlobalEnv)
    if (!(n <- length(last.warning))) 
        return()
    names <- names(last.warning)
    cat(ngettext(n, "Warning message:\n", "Warning messages:\n"),...)
    for (i in 1:n) {
        out <- if (n == 1) 
            names[i]
        else paste(i, ": ", names[i], sep = "")
        if (length(last.warning[[i]])) {
            temp <- deparse(last.warning[[i]])
            out <- paste(out, "in:", temp[1], if (length(temp) > 
                1) 
                " ...")
        }
        cat(out, ..., fill = TRUE)
    }
}




Leif Kirschenbaum
Senior Yield Engineer
Reflectivity, Inc.
(408) 737-8100 x307
leif at reflectivity.com



[Rd] request to add "..." to cat(ngettext in "warnings" function
Leif Kirschenbaum