[Rd] Package options

Prof Brian Ripley ripley at stats.ox.ac.uk
Wed Feb 3 14:43:22 CET 2010

A number of packages do this.  See e.g. 'sm' and its function 
sm.options() for one implementation.

On Wed, 3 Feb 2010, Duncan Murdoch wrote:

> On 03/02/2010 8:07 AM, Chris Brien wrote:
>> Dear all,
>> I am developing a package foo that has a namespace. I would like to be able 
>> to provide an option, say opt, that 
>> 1) is set to a default value when the package is loaded
>> 2) can be set to a different value by the package user
>> 3) is used by functions within the package
>> How can I achieve this?
> Do you want this option to persist to the next session if a user saves the 
> workspace?  If so, then it should be stored in a variable in the global 
> environment.  You can use assign(".FooOptions", value, envir=globalenv()) to 
> set it, and get(".FooOptions", envir=globalenv())
> to read it.
> The obvious problem with this is that the user might already have a 
> .FooOptions variable defined, and your code would stomp on it.  An 
> alternative is to store the variable into the namespace.  You need to unlock 
> it to change it.  See tools:::startDynamicHelp for code that does this for 
> the variable httpdPort.
> Duncan Murdoch
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

More information about the R-devel mailing list