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