[R] setting options in a list

From: Michael Toews <mwtoews_at_sfu.ca>
Date: Mon 23 Oct 2006 - 05:08:12 GMT


Hi,
I have a question regarding setting options that use a list. There are none that I'm aware of in R-base, however, it can make sense for some custom situations. For example:
 options(myoptions=list(lwd=1,density=NULL,angle=45,col="green")) Getting values is simple:
 getOption("myoptions")$col
However, setting a value from the list is less intuitive; here are a few failed attempts that could make sense from an intuitive level:  setOption("myoptions")$col <- "red" # non-existing function  options("myoptions")[[1]]$col <- "red"
Here is an attempt that almost works, but as documented, it only sets a local .Options object for S-compatibility:
.Options["myoptions"][[1]]$col <- "red"
.Options["myoptions"][[1]]$col # works, but ...
 getOption("myoptions")$col

The only method I know of is to modify a copy of the list from the options, then re-set the option:
 cp <- getOption("myoptions")
 cp$col <- "red"
 options("myoptions"=cp)
 getOption("myoptions")$col

So, my question is if there is a more elegant method of setting an option in a list, that doesn't need copying and multiple commands? Having a 'setOption' function sure could be helpful for this instance, however I'm unsure how to implement this method (or if it is possible in the current version of R).
Thanks.
+mt



R-help@stat.math.ethz.ch 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. Received on Mon Oct 23 15:14:02 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Mon 23 Oct 2006 - 06:30:13 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.