[R] Error in summary.warnings?

Martin Maechler m@ech|er @end|ng |rom @t@t@m@th@ethz@ch
Fri May 8 17:37:29 CEST 2020


>>>>> Allison Meisner 
>>>>>     on Thu, 7 May 2020 19:32:36 +0000 writes:

    > I believe there is an error in the summary.warnings function (typically called via 'summary(warnings())'). Below is a minimal working example:
    > #########

    > testfunction <- function(x){
    >  if(x > 30){
    >      warning("A big problem (should be 20 of these)")
    >  }else{
    >      warning("Bigger problem (should be 30 of these)")
    >  }
    > }

    > for(i in 1:50){
    >     testfunction(i)
    > }

    > summary(warnings())

    > #########

    > I checked the code for summary.warnings:

    > function (object, ...)
    > {
    > msgs <- names(object)
    > calls <- as.character(object)
    > ss <- ": "
    > c.m. <- paste(calls, msgs, sep = ss)
    > if (length(i.no.call <- which(calls == "NULL")))
    > c.m.[i.no.call] <- substr(c.m.[i.no.call], nchar(paste0("NULL",
    > ss)) + 1L, 100000L)
    > tm <- table(c.m., deparse.level = 0L)
    > structure(unique(object), counts = as.vector(tm), class = "summary.warnings")
    > }

    > The problem appears to be in the last line: unique preserves the order of the input, but counts reflects the counts in the table tm, which is a problem because table names are in alphabetical order.

    > Am I missing something?

No -- I think you are perfect and I was very imperfect ;-)  when
I created and tested the function ..

This will be fixed in the next versions of R.

Thank you very much for the report  and the nice concise
reproducible example!

Best regards,
Martin

    > Allison
    > ----------
    > Allison Meisner, PhD
    > Postdoctoral Fellow
    > Department of Biostatistics
    > Johns Hopkins Bloomberg School of Public Health
    > 615 N. Wolfe Street
    > Baltimore, MD 21205

Martin Maechler
ETH Zurich  and   R Core team



More information about the R-help mailing list