Skip to content
Prev 310208 / 398503 Next

problem with package development and older defs earlier in search order

On 12-11-07 7:11 PM, Martin J Reed wrote:
Rolf's advice is good:  delete the copies from your global env, and the 
ones in your package won't be hidden.

Here's some more long term advice:  keep your global environment empty 
at the start of each session, and thereby avoid this problem.  If you 
want to temporarily edit a function from your package, you can still 
make a copy in the global environment, and it will take precedence (when 
called from the top level; the package functions that call each other 
won't see it).  At the end of your session, when offered the chance to 
save your workspace, just say no.

Regarding your specific question:  a package could overwrite user 
objects in the global environment, but that's very bad practice.  The 
user owns those, and packages should avoid messing with them.  Let the 
user say

foo <- foo

to make a copy of the foo function in the global environment, don't 
force your own copy there.  (The user will still be able to get back to 
the original one using the pkg::foo notation, and as I mentioned, 
packages will generally look internally first, so they'll see the 
original one.)

Duncan Murdoch