msberends / AMR

Functions to simplify and standardise antimicrobial resistance (AMR) data analysis and to work with microbial and antimicrobial properties by using evidence-based methods, as described in https://doi.org/10.18637/jss.v104.i03.
https://msberends.github.io/AMR/
Other
83 stars 12 forks source link

Error when antibiogram empty #156

Closed andrewjmc closed 1 month ago

andrewjmc commented 1 month ago

Hello,

It appears that if antibiogram cannot produce any rows (e.g. due to no taxa crossing the minimum threshold) there is an error.

Is this intentional, or would an empty table + a warning be intended?

Traceback

8: (function (..., na.last = TRUE, decreasing = FALSE, method = c("auto", 
       "shell", "radix")) 
   {
       z <- list(...)
       decreasing <- as.logical(decreasing)
       if (length(z) == 1L && is.numeric(x <- z[[1L]]) && !is.object(x) && 
           length(x) > 0) {
           if (.Internal(sorted_fpass(x, decreasing, na.last))) 
               return(seq_along(x))
       }
       method <- match.arg(method)
       if (any(vapply(z, is.object, logical(1L)))) {
           z <- lapply(z, function(x) if (is.object(x)) 
               as.vector(xtfrm(x))
           else x)
           return(do.call("order", c(z, list(na.last = na.last, 
               decreasing = decreasing, method = method))))
       }
       if (method == "auto") {
           useRadix <- all(vapply(z, function(x) {
    ...
7: do.call(order, lapply(pm_groups, function(x) res[, x]))
6: pm_summarise.grouped_data(.data, ...)
5: pm_summarise(out, SI = numerator/total)
4: eval(as.call(c(rhs[[1L]], lhs, as.list(rhs[-1L]))), envir = parent.frame())
3: eval(as.call(c(rhs[[1L]], lhs, as.list(rhs[-1L]))), envir = parent.frame())
2: out %pm>% pm_summarise(SI = numerator/total)
1: antibiogram call
msberends commented 1 month ago

Errors are never intended 😄

Appears to be an ordering error, your error text in 8 is the literal text of the order() function of R itself. I'll look into it!

msberends commented 1 month ago

Found it already. In AMR v3.0, it will show and return like this (I added a nice header and footer for those who have tibble installed 😛).


Normal behaviour, enough rows to show something:

image

Behaviour when the result is an empty data set:

image
msberends commented 1 month ago

Many thanks for pointing this out!

andrewjmc commented 1 month ago

That's great, thanks for the speedy fix!