request to add "..." to cat(ngettext in "warnings" function

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

request to add "..." to cat(ngettext in "warnings" function

Leif Kirschenbaum-4
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))
    last.warning <- get("last.warning", envir = .GlobalEnv)
    if (!(n <- length(last.warning)))
    names <- names(last.warning)
    cat(ngettext(n, "Warning message:\n", "Warning messages:\n"),...)
    for (i in 1:n) {
        out <- if (n == 1)
        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) >
                " ...")
        cat(out, ..., fill = TRUE)

Leif Kirschenbaum
Senior Yield Engineer
Reflectivity, Inc.
(408) 737-8100 x307
[hidden email]

[hidden email] mailing list