Skip to content
Prev 36362 / 63421 Next

as(1:4, "numeric") versus as.numeric(1:4, "numeric")

The problem that you have exposed is that if one uses the *standard* 
form of selectMethod() on function "coerce", this could corrupt the 
intended set of methods used by as().  Of course, no one was expected to 
do this, but it's not caught or warned (as opposed to a direct call to 
coerce(), which does generate a warning).

If people think this is something of sufficient importance to put high 
on the fix-it list, contributions are welcome as always.

However, it seems a really bad idea to start making the definition of 
method selection by inheritance depend in an arbitrary way on which 
function is operated on.  Documenting what selection does is hard enough 
as it is.

A solution localized to the as() computation is to treat the mechanism 
involved in a call to setAsMethod  as something special, and provide 
whatever information is needed via showAsMethods(), or similar.  From a 
tutorial view, it might be good to emphasize that this is NOT the usual 
method dispatch--indeed, the present discussion supports that view.

Method selection in a functional language is a difficult concept, 
particularly for programmers coming from a standard OOP background.  If 
we're going to change it, let's aim to make it simpler, not more 
complicated.  What about getting rid of the kludgy argument 
useInheritance= in a future version, if nobody has a use for it other 
than in as()?  If you look at the code, you'll see that would simplify 
it significantly, and even speed up selection somewhat. There's a change 
I would be happy about!

John
On 4/1/10 2:59 PM, Herv? Pag?s wrote: