Sorry about the incomplete post: gMail just vomited on me. Here's the complete post:
On Mon, Aug 15, 2011 at 7:40 PM, Bert Gunter <bgun...@gene.com> wrote: > FWIW: > > 1. The best reference i know is the discussion in Venables's and > Ripley's "S Programming" book > > 2. VERY BRIEF and INADEQUATE discussion. The general idea is that it > allows one to easily pass down "extra" arguments to the internals of a > function. > > For example, suppose that you want to write a function, fitandplot() > that will fit a linear model to data with multiple covariates and then > plot the fitted values versus each of the covariates, but giving the > user the ability to easily change plot options like point color, line > width, etc.. Then instead of having to specify them all (dozens!) in > the top level function as: > fitandplot = function(formula,data, col, lty, pch, cex, etc. etc.) { ## code thefit <- lm( formula, data=data) prdvals <- predict(thefit) ## code that extract the covariates and in some sort of loop calling them z at each iteration ## LOOP ITERATION plot(prdvals ~ z,col=col,lty=lty, pch=pch, etc. etc.) ## more code } could be more simply and flexibly written as: fitandplot = function(formula,data, ...) { ## code thefit <- lm( formula, data=data) prdvals <- predict(thefit) ## code that extract the covariates and in some sort of loop calling them z at each iteration ## LOOP ITERATION plot(prdvals ~ z, ...) ## the ... arguments just get passed downh ## more code } There's quite a lot more to it than this: the suggestion of an earlier response to use: opt_arglist <- list(...) doesn't always work, for example. As I said, V & R has the best discussion I know of. But this should at least give you the concept, I hope. -- Bert > > > > On Mon, Aug 15, 2011 at 4:47 PM, Carl Witthoft <c...@witthoft.com> wrote: >> I followed a couple threads from the archives and from stackoverflow.com, >> and would like to know: just what is "..." ? What I mean by this is,for >> example, from the point of view of a user running a function in debug mode, >> is "..." an object, or does it exist in the current environment as some >> thingy? >> >> Maybe a better question to ask is: if I were to write some function that >> accepts "..." for its own personal use, how do I access the optional >> arguments? Do I simply have to do a series of 'match' or 'pmatch' on the >> output of list(...) , or is there a more direct way to get at the variables? >> >> If there is a R programmer's manual that discusses this, I'm happy to read >> that, so just let me know. >> >> thanks >> Carl >> >> -- >> ----- >> Sent from my Cray XK6 >> >> ______________________________________________ >> R-help@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. >> > > > > -- > "Men by nature long to get on to the ultimate truths, and will often > be impatient with elementary studies or fight shy of them. If it were > possible to reach the ultimate truths without the elementary studies > usually prefixed to them, these would not be preparatory studies but > superfluous diversions." > > -- Maimonides (1135-1204) > > Bert Gunter > Genentech Nonclinical Biostatistics > 467-7374 > http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm > -- "Men by nature long to get on to the ultimate truths, and will often be impatient with elementary studies or fight shy of them. If it were possible to reach the ultimate truths without the elementary studies usually prefixed to them, these would not be preparatory studies but superfluous diversions." -- Maimonides (1135-1204) Bert Gunter Genentech Nonclinical Biostatistics 467-7374 ______________________________________________ R-help@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.