[R] Unwanted association between a function and a namespace

p_connolly at slingshot.co.nz p_connolly at slingshot.co.nz
Thu Dec 24 00:08:15 CET 2009


Quoting Duncan Murdoch <murdoch at stats.uwo.ca>:

> On 23/12/2009 3:36 PM, p_connolly at slingshot.co.nz wrote:
>> I can't understand how the plyr package is turning up here:
>>

[...]

>> I can understand that lattice would be using grid without having that
>> package loaded, but I can't understand how plyr got there.
>
> One way for this to happen is if you have a copy of a function from plyr
> in your global environment.  The functions in plyr reference its
> namespace, so you'd get it loaded that way.

I've never loaded the plyr package, except for when I used the reshape
package.  It's possible at that time, I had occasion to use a function
I have of the same name as one in the plyr package, but I would not
have saved a copy of either function in the global environment.

>
>>
>> It wouldn't matter if that namespace hadn't become associated somehow
>> with a function I have somewhere else on the search path (thereby
>> rendering the function unfindable).
>
> This doesn't make sense.  If the function is on the search path, it
> doesn't matter what namespace is associated with it:  you'll find it.

Perhaps I need to be more explicit.  The find() function does indeed
find it, and I can edit it in ESS using the normal C-c C-d sequence.
HOWEVER, when I do args() of it, I get the args of the plyr function
-- even when I've not loaded that package.  Trying to use the function
in code ends up calling the plyr function.

> If you have a function with the same name in globalenv() then you'll
> have problems.  The simple solution is to remove it (e.g. rm(f)); a
> better long term solution is to *never* store anything in your workspace
> between sessions.  Start with a clean global environment each time.

I thought I'd found a fix when I specifically loaded plyr and then
detached it with the unload = TRUE argument.  sessionInfo() seems to
show that I had gotten rid of the plyr by namespace, but I still get this:

summarize
function(.data, ...) {
  eval(substitute(data.frame(...)), .data, parent.frame())
}
<environment: namespace:plyr>

Curiouser and curiouser as Alice would say.

--
Patrick Connolly
Plant & Food Research
Mt Albert
Auckland
New Zealand
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~
I have the world`s largest collection of seashells. I keep it on all
the beaches of the world ... Perhaps you`ve seen it.  ---Steven Wright
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~




More information about the R-help mailing list