From hb at stat.berkeley.edu  Tue Oct 20 21:44:01 2009
From: hb at stat.berkeley.edu (Henrik Bengtsson)
Date: Tue, 20 Oct 2009 12:44:01 -0700
Subject: [Rd] Suggestion for exception handling: More informative error
	message for "no applicable method..." (S3)
Message-ID: <59d7961d0910201244n6cf92c58p66f35ef68ce4680@mail.gmail.com>

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.



[Rd] Suggestion for exception handling: More informative error message for "no applicable method..." (S3)
Henrik Bengtsson