Hi, I posted this a week ago on r-help but did not get an answer. So I hope that someone here can help me: I want to define some options for my package the user may change. It would be convenient if the changes could be saved when terminating an R session and recovered automatically on the next package load. Is that possible and if yes, is the standard way to implement this? Thanks, Mark ––––––––––––––––––––––––––––––––––––––– Mark Heckmann Dipl. Wirt.-Ing. cand. Psych. Celler Straße 27 28205 Bremen Blog: www.markheckmann.de R-Blog: http://ryouready.wordpress.com [[alternative HTML version deleted]]
On 20 November 2010 at 17:12, Mark Heckmann wrote: | Hi, | I posted this a week ago on r-help but did not get an answer. So I hope that someone here can help me: | I want to define some options for my package the user may change. | It would be convenient if the changes could be saved when terminating | an R session and recovered automatically on the next package load. | | Is that possible and if yes, is the standard way to implement this? First off: R> fortunes:::fortune("yoda") Evelyn Hall: I would like to know how (if) I can extract some of the information from the summary of my nlme. Simon Blomberg: This is R. There is no if. Only how. -- Evelyn Hall and Simon 'Yoda' Blomberg R-help (April 2005) R> Secondly, what you ask is necessarily rather OS-dependent. So of course it can be done, but probably in way that depend on your local circumstance. Thirdly, and to make this a little more helpful, I frequently use the RSQLite package to cache data across sessions and invocations. For a large example, consider the CRANberries feed (http://dirk.eddelbuettel.com/cranberries/) which stores in SQLite what the the state of the (CRAN) world was the last it got woken up by crontab. I also have a few smaller ad-hoc things at work that do similar things. Depending on your local circumstances you may make this 'cache' of stateful information read or read/write, make it a file on NFS or CIFS or WebDAV, make it a database that can be read as file or over sockets and so. And Yoda still rules. Dirk -- Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
I'm not sure why it was not mentioned do far, but the most obvious solution is to create a special object in the workspace (usually a hidden environment or a list - e.g. .myPackage.options.env). One advantage is that the user has full control over whether it should be save or not as it's tied to the workspace. On load the package can look for it and use it if it is what's expected (e.g., it may be worth using a specific class). That said, in either case I think it's important to make it optional and document it well, because leaving files or objects around when not expected is impolite to say the least. Cheers, Simon On Nov 20, 2010, at 11:12 AM, Mark Heckmann wrote:> Hi, > I posted this a week ago on r-help but did not get an answer. So I hope that someone here can help me: > I want to define some options for my package the user may change. > It would be convenient if the changes could be saved when terminating > an R session and recovered automatically on the next package load. > > Is that possible and if yes, is the standard way to implement this? > > Thanks, > Mark > > ??????????????????????????????????????? > Mark Heckmann > Dipl. Wirt.-Ing. cand. Psych. > Celler Stra?e 27 > 28205 Bremen > Blog: www.markheckmann.de > R-Blog: http://ryouready.wordpress.com > > > > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel
On Sat, Nov 20, 2010 at 11:12 AM, Mark Heckmann <mark.heckmann at gmx.de> wrote:> Hi, > I posted this a week ago on r-help but did not get an answer. So I hope that someone here can help me: > I want to define some options for my package the user may change. > It would be convenient if the changes could be saved when terminating > an R session and recovered automatically on the next package load. > > Is that possible and if yes, is the standard way to implement this? >You can use options and getOptions for this. The user can place an options command in their .Rprofile or just enter it into their session to override the defaults. See ?options . For example, in the gsubfn package look at the engine argument:> library(gsubfn)Loading required package: proto> args(gsubfn)function (pattern, replacement, x, backref, USE.NAMES = FALSE, ignore.case = FALSE, engine = getOption("gsubfn.engine"), env = parent.frame(), ...) The user can put an options(engine = "...whatever...") in their .Rprofile file or can enter it interactively into R. If not, getOption("gsubfn.engine") returns NULL and the gsubfn package can check whether engine was passed as a NULL and supply a default. -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com
Seemingly Similar Threads
- all extended ASCII characters exist for R console output?
- Roxygen examples in DONTRUN mode - how?
- evaluate variable within expression - how?
- Reordering the results from table(cut()) by break argument
- changing a list element's name during execution in lapply - possible?