[Rd] how to store package options over sessions?

Gabor Grothendieck ggrothendieck at gmail.com
Mon Nov 22 17:34:59 CET 2010

On Sat, Nov 20, 2010 at 11:12 AM, Mark Heckmann <mark.heckmann at gmx.de> wrote:
> Hi,
> I posted this a week ago on r-help but did not get an answer. So I hope that someone here can help me:
> I want to define some options for my package the user may change.
> It would be convenient if the changes could be saved when terminating
> an R session and recovered automatically on the next package load.
> Is that possible and if yes, is the standard way to implement this?

You can use options and getOptions for this.  The user can place an
options command in their .Rprofile or just enter it into their session
to override the defaults.  See ?options .  For example, in the gsubfn
package look at the engine argument:

> library(gsubfn)
Loading required package: proto
> args(gsubfn)
function (pattern, replacement, x, backref, USE.NAMES = FALSE,
    ignore.case = FALSE, engine = getOption("gsubfn.engine"),
    env = parent.frame(), ...)

The user can put an options(engine = "...whatever...") in their
.Rprofile file or can enter it interactively into R.  If not,
getOption("gsubfn.engine") returns NULL and the gsubfn package can
check whether engine was passed as a NULL and supply a default.

Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

More information about the R-devel mailing list