Skip to content
Prev 46294 / 63461 Next

How to best implement package options?

On Jul 26, 2013, at 9:59 AM, Bj?rn-Helge Mevik wrote:

            
That is certainly not a good way. If you have the urge to use unlockBinding() or assign*Namespace() then think again as your design is likely bad. If you want to store package-local information, simply create an environment in your package - it's this simple:

.myenv <- new.env(TRUE, emptyenv())

The environment is independent of the namespace (you don't export it) and thus you don't need any ugly hacks. The code in your package can manipulate it directly, while the user cannot easily mess with it.
Personally, I hate when packages use their own option management system because it leads to vastly inconsistent behavior, so I prefer using the options() as that is transparent and well defined. But that is just my personal opinion.

Cheers,
Simon