[Rd] Suggestion for exception handling: More informative error message for "no applicable method..." (S3)
Henrik Bengtsson
hb at stat.berkeley.edu
Tue Oct 20 21:44:01 CEST 2009
I'd like to suggest that whenever there is no S3 method implementation
available for a particular class, that the error message would also
report the class structure of the object dispatched on.
Example:
foo <- function(...) UseMethod("foo")
foo.ClassA <- function(object, ...) { cat("foo() for ClassA called.\n") }
> foo(structure(1, class="ClassA"))
foo() for ClassA called.
Now:
> foo(NULL)
Error in UseMethod("foo") : no applicable method for "foo"
> foo(Sys.time())
Error in UseMethod("foo") : no applicable method for "foo"
Suggestion:
> foo(NULL)
Error in UseMethod("foo") : no applicable foo() method: list
> foo(Sys.time())
Error in UseMethod("foo") : no applicable foo() method: POSIXt, POSIXct
This would really help troubleshooting, especially when running in
batch mode where you don't have direct access to the object without
modifying the script and/or functions.
/Henrik
PS. I know that one as a workaround can create a "default" method that
reports this, but I believe it is much better that the builtin
exception handling should report this/carry this information.
More information about the R-devel
mailing list