Skip to content
Prev 36791 / 63424 Next

Is it possible to generate an error when a function is reassigned?

thmsfuller066 at gmail.com wrote:
You aren't changing length(), you're creating a new function with the 
same name that hides the original one.  The distinction is important 
because packages with namespaces will not be affected by your error, 
it's not really as serious as you might think.

The general advice to protect yourself from mistakes like this is to 
limit how much of your code you keep in the global environment.  Keep 
your code in scripts and source them into an empty environment, or 
(better) put your code into a package and use a namespace.  If you make 
a mistake and hide an important function you'll still cause local 
problems, but you may find it easier to fix them.

Duncan Murdoch