Skip to content
Prev 327936 / 398500 Next

import function without overwriting function with the same name

Martrin:

It sounds like you have some homework to do. Moreover, you have not
provided sufficient information (for me, anyway) to give a definitive
answer: why/how are the functions different? How are they used?

1) "Import" is not the same as "source."  "Import" is something one
does with packages. Packaging up your functions sensibly and using
Namespaces and import directives appropriately may be how you should
proceed (I would say "probably" is, except you have not provided
sufficient information). So you need to read up on R package creation
and Namespaces.

2. Alternatively, perhaps you should make your different functions
with the same name methods for the different classes to which they are
applicable using either the S3 or S4 class system. So you may need to
read up on these class systems and method invocation.Again, impossible
to say without more info.

3. Or maybe you need to combine your separate functions into one with
appropriate default and optional argument lists that alter the
execution, e.g. via having arguments that are functions that alter the
behavior. This is one of the glories of functional programming
(functions are first class objects).

4. Or, probably the least desirable approach that may nevertheless be
what you may want, is just to attach your collections of functions and
access them by fully qualified names. See ?"::" for details on how to
do that.

... or maybe something else that I haven't thought of or that would
fit your needs better. But without having those needs specified in
detail, ???

Cheers,
Bert
On Sat, Aug 3, 2013 at 1:27 PM, Martin Batholdy <batholdy at googlemail.com> wrote: