From murdoch at stats.uwo.ca  Wed Feb  3 14:34:42 2010
From: murdoch at stats.uwo.ca (Duncan Murdoch)
Date: Wed, 03 Feb 2010 08:34:42 -0500
Subject: [Rd] Package options
In-Reply-To: <EC96E350A5D6444B82CBD8DA338F017508A107AF@ITUPC-EX1MBOX.UniNet.unisa.edu.au>
References: <EC96E350A5D6444B82CBD8DA338F017508A107AF@ITUPC-EX1MBOX.UniNet.unisa.edu.au>
Message-ID: <4B697B72.4020208@stats.uwo.ca>

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



[Rd] Package options
Duncan Murdoch