Official way to set/retrieve options in packages?
Have you read ?Startup which explains startup procedures, including reading of .Rprofile. I cannot speak for Brian Ripley, but I can tell you that I would prefer that packages did not mess with my .Rprofile files. OTOH, I have no objections if packages suggest that I set certain options in them or even give me lines of code that I can add if I choose ( or give me an option to call a function to do so). I understand that this is not the automatic procedure you seem to be seeking... Cheers, Bert
On Sun, Jun 2, 2013 at 9:06 AM, Jonathan Greenberg <jgrn at illinois.edu> wrote:
What would be an example of setting, saving, and re-loading an option to a user's .Rprofile -- and would this be a no-no in a CRAN package? --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 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.
Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm