Skip to content
Prev 23987 / 63424 Next

How to override functions in namespaces?

On 2/12/2007 1:13 PM, jhallman at frb.gov wrote:
There are several ways.  If package A "knows" that some users will want 
to replace askForString(), then it should allow the user to tell it what 
to use for that function, and fall back to its own definition as a 
default.  It could do this by explicitly looking for askForString in the 
global environment (which will fall back to the search list if not 
found), or it could get the function from an option() setting, etc.

If package A doesn't expect askForString() to be changed, then you 
shouldn't change it:  you might break something else in A.  You should 
write to the author of A (which sounds as though it's yourself), and ask 
for some improvements to the package.

There are dirty methods to modify the contents of a namespace, but you 
shouldn't use those.

Duncan Murdoch