[Rd] Multiple options for a package

Eric Lecoutre lecoutre at stat.ucl.ac.be
Tue Dec 14 11:52:16 CET 2004

Hi R-devel,

I am facing a situation where the number of options I would like to propose 
to the user is somewhat big (and could easily increase more and more as I 
will code up a little more - even coming to a point where an user should be 
able to implement his own options).

What we have to handle options is the couple:
options(par=value) and getOption("par")

I was aking myselft what would be the "better" strategy to handle a bunch 
of options for a package.

I ended up with the idea of storing a list, as my options would also be 
classified, with something like:

MyPkgOptions = 

Then, to make easier the access to an element, I tweaked a little bit 
getOption, with the following version:

getOption <- function(x,...)
   op = options(x)[[1]]
   if (length(list(...))>0) op <- op[[c(...)]]

Making possible calls like:

[1] 111

Then, I began to implement things 
like  SetPkgOption(pkg,value=NULL,pathToValue) and 

But I wonder if this wont be easier / more efficient at the C level. Sorry: 
I dont propose myself to make it, as my C skills are nearly null.

To recap:

- I need a way to set/get a lot of options for a package
- I am ready to go on with my appraoch, delivering at the end some R functions
- Seeing the way options() are handled with the internal call, I wonder if 
my idea is the better one
- Specifically, I think someone with greater C skills should be able to set 
up functions like PkgOptions
- I would like to hear about any other idea that would better suit me needs

Best wishes,


PS: I think handling options at a package level would be a benefit for the 
user. Setting options would be done within .First or .onLoad when we know 
the package name. The options() tree would be far more readable, separating 
core options from others. Two weeks ago, i ended up with a list of 125 

PS2: an other related topic is Saving/Restore options. For my personal 
needs (testing within a session), I coded following functions:

saveOptions <- function(file="R.options",...){

restoreOptions <- function(file="R.options"){
   if (!file.exists(file))
     warning(paste("file ", file, " does not exist"))
   opts = get("opts",envir=.tmp)

Same scheme could be used for a set of options (say options for a package). 
Any comment on the above code?

More information about the R-devel mailing list