Skip to content
Prev 27796 / 63424 Next

Generic Functions

Thanks a lot for your explanation, which I higly appreciate. But I have
still a problem...

Think about 2 persons, each of them create their own package. Both define a
generic function "setType" with different arguments. 

Person 1: setType(obj, valX)
Person 2: setType(spec)

If I require the package of person 1, everything works fine.

If I call the second package afterwards, I will get an error, because the
generic function already exists.

How can I solve this conflict? How can I define a new generic function which
has different arguments without getting in trouble with the first package?
Is there a way to define functions, which belongs to a specific class
without getting in troubles with other packages?

Thanks a lot for your help.
Dominik


-----Urspr?ngliche Nachricht-----
Von: Martin Morgan [mailto:mtmorgan at fhcrc.org] 
Gesendet: Montag, 25. Februar 2008 19:54
An: Dominik Locher
Betreff: Re: AW: [R] Generic Functions

Things are different in R. You can't protect a new function from hiding your
function, just as
[1]  1  2  3  4  5  6  7  8  9 10
[1] "oops"
[1]  1  2  3  4  5  6  7  8  9 10

Note that the redefinition hides but does not remove 'print' function.

Generics don't really belong with classes, but if you think about it
something like

class Foo {
        function bar() {}
    }

foo = new Foo;
$foo->bar()

in php is very similar to
i.e., set a method on the generic function. Someone could write another
method 'bar' operating on a different object, and it would coexist with your
method.

Martin

"Dominik Locher" <dominik.locher at bondsearch.ch> writes:
;-).