hope this helps..  :)

    # define an object `x`
    x <- list( "any value here" , 10 )

    # set `myoption` to that object
    options( "myoption" = x )

    # retrieve it later (perhaps within a function elsewhere in the package)
    ( y <- getOption( myoption ) )


it's nice to name your options `mypackage.myoption` so users know what
package the option is associated with in case they type `options()`


here's the `.onLoad` function in the R survey package.  notice how the
options are only set *if* they don't already exist--

> survey:::.onLoad

function (...)
{
    if (is.null(getOption("survey.lonely.psu")))
options(survey.lonely.psu = "fail")
    if (is.null(getOption("survey.ultimate.cluster")))
options(survey.ultimate.cluster = FALSE)
    if (is.null(getOption("survey.want.obsolete")))
options(survey.want.obsolete = FALSE)
    if (is.null(getOption("survey.adjust.domain.lonely")))
options(survey.adjust.domain.lonely = FALSE)
    if (is.null(getOption("survey.drop.replicates")))
options(survey.drop.replicates = TRUE)
    if (is.null(getOption("survey.multicore")))
options(survey.multicore = FALSE)
    if (is.null(getOption("survey.replicates.mse")))
options(survey.replicates.mse = FALSE)
}
<environment: namespace:survey>




On Sat, Jun 1, 2013 at 4:01 PM, Jonathan Greenberg <j...@illinois.edu>wrote:

> R-helpers:
>
> Say I'm developing a package that has a set of user-definable options that
> I would like to be persistent across R-invocations (they are saved
> someplace).  Of course, I can create a little text file to be written/read,
> but I was wondering if there is an "officially sanctioned" way to do this?
>  I see there is an options() and getOptions() function, but I'm unclear how
> I would use this in my own package to create/save new options for my
> particular package.  Cheers!
>
> --j
>
> --
> Jonathan A. Greenberg, PhD
> Assistant Professor
> Global Environmental Analysis and Remote Sensing (GEARS) Laboratory
> Department of Geography and Geographic Information Science
> University of Illinois at Urbana-Champaign
> 607 South Mathews Avenue, MC 150
> Urbana, IL 61801
> Phone: 217-300-1924
> http://www.geog.illinois.edu/~jgrn/
> AIM: jgrn307, MSN: jgrn...@hotmail.com, Gchat: jgrn307, Skype: jgrn3007
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to