[R] Error in summary.warnings?
Allison Meisner
@me|@ne1 @end|ng |rom jhm|@edu
Thu May 7 21:32:36 CEST 2020
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?
Allison
----------
Allison Meisner, PhD
Postdoctoral Fellow
Department of Biostatistics
Johns Hopkins Bloomberg School of Public Health
615 N. Wolfe Street
Baltimore, MD 21205
[[alternative HTML version deleted]]
More information about the R-help
mailing list