[R] import function without overwriting function with the same name

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Sat Aug 3 23:26:34 CEST 2013


This kind of thing gets dealt with as part of building packages. You can patch together your own namespace management (?attachNamespace) but you are better served to start developing your functions into packages once your projects get large enough that you start worrying about name collisions.
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.

Martin Batholdy <batholdy at googlemail.com> wrote:
>Hi,
>
>I have to import multiple R-files.
>Each file consists of several functions with the same function name
>across the R-files.
>
>When I import all files one by one (with source()) I overwrite the
>function definition of the previous file until only the very last
>function definition lasts.
>However, I need them separately (although they have the name, they
>solve a certain task differently).
>
>Now I thought about creating a separate environment for each file /
>function-group, but I do not know upfront how many files I have to
>import and therefore how many different environments I need.
>But since the creation of an environment works like variable
>assignments (myEnv <- new.env()) I cannot just loop over the number of
>files and create x environments.
>
>What is the best way to solve this problem of importing functions
>without overwriting already existing functions with the same name?
>
>
>Thanks!
>______________________________________________
>R-help at r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list