[R] moving functions between namespaces
Douglas Bates
bates at stat.wisc.edu
Sat Oct 16 18:22:59 CEST 2004
Faber Fedor wrote:
> Hi all,
>
> I'm a newbie wrt R but that's okay, since I don't do any programming
> in R. What I do need to do is to administrate the activites of an R
> programmer, so my questions will be related to adminning R as opposed
> to statistcal programming. I hope that's okay with y'all. :-)
>
> I've been through most of the docs that I could find (the PDFs,
> StatsRUs, etc.) and I've found the answers to most of my questions,
> but not to an important one: how do I move a function from one
> namespace to another.
>
> On the chance that I'm not using the right terminlogoy, here's my
> situation: Programmer A has written a function foobar() which resides
> in his namespace /home/progA/.RData. I want to move foobar(), and
> only foobar(), into the QA enviroment which means replicating foobar()
> inside of /home/qa/.RData.
>
> I've found that I can use sink() to copy foobar() to a file but 1) I
> haven't found how to read it back in and 2) I figure you guys have a
> more elegant way of doing this.
>
> Any advice?
The term "namespace" now means something other than the way you use it
but that's not important.
The simple way to do this is to have Programmer A start up R in
/home/progA and save a copy of the function foobar to a file.
save(foobar, file = "/home/qa/foobar.rda")
(Depending on the size of the file Programmer A may wish to add the
optional argument compress = TRUE in that call.)
Now start R in /home/qa and load the saved copy
load("/home/qa/foobar.rda")
then exit R.
I'm tempted to write more about variations on this mechanism but I think
I'll just stay with the simple answer.
More information about the R-help
mailing list