[R] updating a helper function in a R package

Gabor Grothendieck ggrothendieck at gmail.com
Thu Dec 6 23:44:02 CET 2007


If you are using namespaces see:

?assignInNamespace

On Dec 6, 2007 5:38 PM, Tao Shi <shitao at hotmail.com> wrote:
>
> Hi list,
>
> Sorry for the vague title, but here is the scenario.
>
> I'm writing an R package, let's say, 'pkg1', which contains 3 functions: f1, f2, f3.  f2 and f3 are helper functions for f1, i.e. f1 calls f2 which in turn calls f3.
>
> f1 <- function(…) {
>        ….
>        f2()
>> }
>
> f2 <- function(…){
>>        f3(…)
>> }
>
> f3 <- function(...){
>       ....
> }
>
> Then, I wrote a new version of f3 and I want to test it.  With the old version of 'pkg1' already loaded into my R session, I tried just copy-and-paste the new 'f3' to R console and hope f1 will pick the new 'f3' up.  It obviously didn't work.  I know it's b/c the new f3 and old f3 are in different environments and when f1 is called, only old f3 is used.  Then I tried to change the environment of new f3 to the same as the old f3's by calling:
>
> environment(f3) <- environment(pkg1:::f3)
>
> but it wasn't working either.
>
> So,
> 1)      Could somebody help me to put all these into perspectives?
> 2)      Is there an easier way to update f3 without rebuilding the package? (by that I mean, writing the new version of f3 in a way that I only need to copy-and-paste to R console and I'm good to go.  I know it's kind of stupid but I'm curious to know)
>
> I'm using R-2.5.1, on WinXP.
>
> Many thanks,
>
> …Tao
>
>
> _________________________________________________________________
>
>
> 07
> ______________________________________________
> 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