Re: [Rd] NAMESPACE Q: does import as exist?

From: Duncan Murdoch <murdoch_at_stats.uwo.ca>
Date: Wed 08 Feb 2006 - 12:08:23 GMT

On 2/7/2006 9:10 PM, Duncan Murdoch wrote:
> On 2/7/2006 8:48 PM, Seth Falcon wrote:

>> Is there a way to rename a function when importing it?  I want to say,
>> "import yourFunc from Foo as myFunc" in the NAMESPACE file.  
>>
>> Does this exist and I've missed it?  If it doesn't exist, would others
>> think it useful (and possible)?

>
> I don't know if that exists, but importing it and then copying it should
> work. That is, in your namespace import foo, and export bar, and in one
> of your R source files have
>
> bar <- foo

There may be a disadvantage to this if you have a saved image of the function -- the current one will be saved, not the one that gets a bug fixed next week. Or maybe it's okay, I don't know. I think a way around that problem would be

delayedAssign("bar", foo)

which won't actually do the copying until the first use of bar.

As Romain said, if there are multiple foo functions around, just qualify the name before importing.

Duncan Murdoch



R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Wed Feb 08 23:33:30 2006

This archive was generated by hypermail 2.1.8 : Wed 08 Feb 2006 - 18:58:44 GMT