[R] Official way to set/retrieve options in packages?

Bert Gunter gunter.berton at gene.com
Sat Oct 19 01:53:33 CEST 2013


1. I do not recall saying any such thing.

2. HOWEVER, no matter. There is no choice. Follow Brian's advice.

-- Bert

On Fri, Oct 18, 2013 at 3:46 PM, Jonathan Greenberg <jgrn at illinois.edu> wrote:
> Wanted to re-start this thread a bit, since I'm still not exactly sure
> the best approach to my problem -- basically, the parameters I'm try
> to make persistent are installation locations of a particular command
> line program that is not installed along with an R package I'm working
> on (GDAL, for those of you who are interested in the specifics).  The
> function tries to dummy-proof this process by doing a (mostly)
> brute-force search of the user's drive for the program location the
> first time it executes, and then stores this information (the path to
> a given executable) in an option for use with other functions.   This
> search process can take some time, so I'd prefer to have this option
> set in a semi-permanent way (so it persists between sessions).
>
> Now, Brian Ripley suggested modifying the .Rprofile, but Bert Guntner
> suggested this might not be a welcome behavior.  Given that, on an
> operating system level, there are often per-program directories for
> preferences, would it follow that it might make sense to store
> package-options in some standardized location?  If so, where might
> this be?  Would it make sense to drop then in the package directory?
>
> Is this a discussion that should move over to r-developers?
>
> --j
>
> On Sat, Jun 1, 2013 at 4:57 PM, Prof Brian Ripley <ripley at stats.ox.ac.uk> wrote:
>> On 01/06/2013 22:44, Anthony Damico wrote:
>>> 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--
>>
>> But a nicer convention is that used by most packages in R itself: if the
>> option is not set, the function using it assumes a suitable default.
>> That would make sense for all the FALSE defaults below.
>>
>> Note though that this is not 'persistent': users have to set options in
>> their startup files (see ?Startup).   There is no official location to
>> store package configurations.  Users generally dislike software saving
>> settings in their own file space so it seems very much preferable to use
>> the standard R mechanisms (.Rprofile etc).
>>
>>>
>>>> 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 <jgrn at 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: jgrn307 at hotmail.com, Gchat: jgrn307, Skype: jgrn3007
>>>>
>>>>          [[alternative HTML version deleted]]
>>>>
>>>> ______________________________________________
>>>> R-help at 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 at 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.
>>>
>>
>>
>> --
>> Brian D. Ripley,                  ripley at stats.ox.ac.uk
>> Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
>> University of Oxford,             Tel:  +44 1865 272861 (self)
>> 1 South Parks Road,                     +44 1865 272866 (PA)
>> Oxford OX1 3TG, UK                Fax:  +44 1865 272595
>
>
>
> --
> 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
> 259 Computing Applications Building, MC-150
> 605 East Springfield Avenue
> Champaign, IL  61820-6371
> Phone: 217-300-1924
> http://www.geog.illinois.edu/~jgrn/
> AIM: jgrn307, MSN: jgrn307 at hotmail.com, Gchat: jgrn307, Skype: jgrn3007
>
> ______________________________________________
> R-help at 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.



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

(650) 467-7374



More information about the R-help mailing list