Skip to content
Prev 61811 / 63424 Next

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

My thinking is the signature of the internal .InheritForDispatch() is
not likely to help anyone,
in fact having the opposite effect for beginners unsure how to use that info.
Sure, here are a few.

library(Matrix)
# searching for Matrix-owned generics
matrix_generics <- getGenerics(where = asNamespace("Matrix"))
matrix_generics at .Data[matrix_generics at package == "Matrix"]

# simple signature, one argument 'x'
symmpart()
# Error: unable to find an inherited method for function ?symmpart?
for signature ?x="missing"?

# more complicated signature, especially including ...
Cholesky(a = 1)
# Error: unable to find an inherited method for function ?Cholesky?
for signature ?A="missing"?
Cholesky(a = 1, perm = TRUE)
# Error: unable to find an inherited method for function ?Cholesky?
for signature ?A="missing"?
Cholesky(a = 1, perm = TRUE, IMult = 2)
# Error: unable to find an inherited method for function ?Cholesky?
for signature ?A="missing"?

---

'base' is a bit harder since stats4 just provides classes over stats
functions, so the missigness error comes from non-S4 code.

library(stats4)
coef()
# Error in coef.default() : argument "object" is missing, with no default

Defining our own generic:

setGeneric("BaseGeneric", \(a, ...) standardGeneric("BaseGeneric"))
BaseGeneric()
# Error: unable to find an inherited method for function ?BaseGeneric?
for signature ?a="missing"?

# getting multiple classes to show up requires setting the signature:
setMethod("BaseGeneric", signature(x = "double", y = "double"), \(x,
y, ...) x + y)
BaseGeneric(X = 1, Y = 2)
# Error: unable to find an inherited method for function ?BaseGeneric?
for signature ?x="missing", y="missing"?


On Fri, Aug 11, 2023 at 2:26?AM Martin Maechler
<maechler at stat.math.ethz.ch> wrote: