[Rd] Suggestions for an "official" place to store permissions/options for a package?

Duncan Murdoch murdoch.duncan at gmail.com
Sat Oct 19 14:06:51 CEST 2013


On 13-10-18 8:32 PM, Jonathan Greenberg wrote:
> R-developers:
>
> Duncan Murdoch suggested I move a post I started on r-help over here,
> since it is more at the developer level.  Here is my
> question/challenge -- to my knowledge, there is not currently an
> official way to store a *package*'s options to a standardized location
> on a user's computer.  Given that OS-level programs have standard
> preference locations, I was hoping to first assess:
>
> - Does R, in fact, have a place for a *package* to store preferences
> (a file-based "setOptions") that would be persistent across sessions.
>
> One suggestion that was given was to perhaps write these options to
> the .RProfile, but this strikes me as potentially dangerous -- a
> poorly written function to write to a user's .RProfile could corrupt
> it.

I think you misread that suggestion.  I think it was a suggestion that 
the user should write that information into their own .RProfile.

What I'd suggest you do is have two functions, saveFooOptions and 
loadFooOptions in your package Foo. (The exact names aren't important, 
but don't use generic names like saveOptions and loadOptions; other 
packages may want to follow your model.)  Instruct the user to set the 
options in a session, then call saveFooOptions to save them.  Tell them 
how to put loadFooOptions into their .RProfile file if they want them 
loaded automatically at startup.

Currently the only files that R writes automatically are .RData and 
.RHistory. It only writes those after confirmation from the user, and 
they are not written to a standard location, so users can maintain 
multiple copies of them.  Packages should be no more intrusive.

On Windows, the R GUI maintains a collection of preferences, but they 
are never written automatically.  The loadRconsole() function can load 
them from an arbitrary file; they are saved from a dialog in the GUI. 
There's a default set in the R install directory, but often users don't 
have write permission there.  You could do the same, having a default 
set of options in your package installation, but you shouldn't assume 
the user has rights to change it.


> If the answer to the initial question is "no" (there is not an
> official location/approach for a package to store its own files), I'd
> like to suggest we open this for a wider discussion amongst the
> developers, to perhaps come up with a general (not package-by-package)
> solution for a package to store options (and perhaps other files) in a
> standard location.
>
> The particular application that has brought me to asking about this is
> that I'm writing a package that has external calls to command-line
> programs that may not be properly registered with a user's environment
> (think: Windows, in particular, although I've found issues with a Mac
> as well), so the first step of these R - wrapper functions is to
> search a user's local machine for the binaries.  If it finds it, it
> stores the path to this binary as an option.  Since this is a
> brute-force search, this can take some time and, ideally, this
> information would be preserved across sessions, without the function
> having to re-search their drive every time they start R fresh.

That sounds like a case where a user might choose to save the locations. 
  But you shouldn't do it without asking, and you should allow the user 
to decide where the file goes.

Duncan Murdoch



More information about the R-devel mailing list