Skip to content
Prev 61808 / 63424 Next

Improving user-friendliness of S4 dispatch failure when mis-naming arguments?

Here's a trivial patch that offers some improvement:

Index: src/library/methods/R/methodsTable.R
===================================================================
--- src/library/methods/R/methodsTable.R (revision 84931)
+++ src/library/methods/R/methodsTable.R (working copy)
@@ -752,11 +752,12 @@
   if(length(methods) == 1L)
     return(methods[[1L]]) # the method
   else if(length(methods) == 0L) {
-    cnames <- paste0("\"", vapply(classes, as.character, ""), "\"",
+    cnames <- paste0(head(fdef at signature, length(classes)), "=\"",
vapply(classes, as.character, ""), "\"",
      collapse = ", ")
     stop(gettextf("unable to find an inherited method for function %s
for signature %s",
                   sQuote(fdef at generic),
                   sQuote(cnames)),
+         call. = FALSE,
          domain = NA)
   }
   else

Here's the upshot for the example on DBI:

dbGetQuery(connection = conn, query = query)
Error: unable to find an inherited method for function ?dbGetQuery?
for signature ?conn="missing", statement="missing"?

I don't have any confidence about edge cases / robustness of this
patch for generic S4 use cases (make check-all seems fine), but I
don't suppose a full patch would be dramatically different from the
above.

Mike C
On Thu, Aug 10, 2023 at 12:39?PM Gabriel Becker <gabembecker at gmail.com> wrote: