Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Standard mechanism to have package-specific options in R?

In my scripts, which I am currently making into a package, a number of "global settings" are needed. Currently, these settings are in global variables and were usually changed by editing the script directly. (The script produces entries for a database, and you need to adjust stuff like "author name" and other custom "constant" part of the entries.)

Again, currently I used const_author <- "Meow The Scientist Cat"et al. I can, of course, leave this exactly as is, and export all the global variables, so the user can set them to whatever. However, this is ugly, and pollutes the namespace.

What is the standard method in R to make such settings available to the user? Using options()? And at which point in the package should these options be loaded?

Maybe using a function like settingsTemplate(filename) which exports a file with default settings, which the user then can customize; and he has to source the file or loadSettings (filename) before using the scripts?

like image 813
meow Avatar asked Mar 12 '12 08:03

meow


1 Answers

You could create something similar to xcms: in zzz.R we call .setXCMSOptions (from init.R upon package loading, where xcms specific options are inserted into the generic BioC options:

getOption("BioC")$xcms

You could provide getter and setter methods for your options.

like image 184
sneumann Avatar answered Nov 09 '22 19:11

sneumann