Skip to content
Prev 388997 / 398506 Next

What if there's nothing to dispatch on?

On Wed, 1 Sep 2021 05:35:03 -0400
Duncan Murdoch <murdoch.duncan at gmail.com> wrote:

            
Thanks Duncan. I don't understand your warning, but.

If I call foo(y ~ x,data=xxx) I want the generic to dispatch to the
formula method.  That method will then look for y and x first in xxx,
and if it can't find them there it then will look for them in the global
environment.

If I call foo(x,y,data=xxx) I want the generic to dispatch to the
default method, irrespective of whether x exists in the global
environment.  I can't figure out how to arrange this.  As before
(if I could arrange for the dispatch to happen as desired) I would want
the method to look for y and x first in xxx, and if it can't find them
there it then will look for them in the global environment.

It doesn't matter there is an "x" in both xxx and in the global
environment; the methods will/should use the "x" from xxx.

I don't see a problem with respect to this issue.

Whatever.  I can't get your shoot-in-the-foot solution to work anyway.

If I set

    xxx <- data.frame(u=1:10,v=rnorm(10))

and do

    foo(x=u,y=v,data=xxx)

I get
The argument names need to match up.  Note that calling foo.default()
directly works:

    foo.default(x=u,y=v,data=xxx)

runs just fine.

I think I'm going to have to give up on the classes-and-methods
approach.  I *think* I can see a way through with a using a single
function and if-statements based on your "try" idea.

Thanks!!!

cheers,

Rolf