Ravi Varadhan
2008-Mar-13 16:05 UTC
[R] Use of ellipses ... in argument list of optim(), integrate(), etc.
Hi, I have noticed that there is a change in the use of ellipses or . in R versions 2.6.1 and later. In versions 2.5.1 and earlier, the . were always at the end of the argument list, but in 2.6.1 they are placed after the main arguments and before method control arguments. This results in the user having to specify the exact (complete) names of the control arguments, i.e. partial matching is not allowed. An example with integrate() :> integrate(function(x) exp(-x^2), lower=-Inf, upper=L, subdiv=1000)Error in f(x, ...) : unused argument(s) (subdiv = 1000)> integrate(function(x) exp(-x^2), lower=-Inf, upper=L, subdivisions=1000)1.633051 with absolute error < 1.6e-06 Here is an example with optim():> res <- optim(50, fw, meth="BFGS", control=list(maxit=20000, temp=20,parscale=20)) Error in fn(par, ...) : unused argument(s) (meth = "BFGS") FYI, I am using R version 2.6.1 on Windows XP. May I ask what the rationale behind this change is and also about the pros and cons of the two different ways of specifying (.)? Thank you very much. Best, Ravi. ---------------------------------------------------------------------------- ------- Ravi Varadhan, Ph.D. Assistant Professor, The Center on Aging and Health Division of Geriatric Medicine and Gerontology Johns Hopkins University Ph: (410) 502-2619 Fax: (410) 614-9625 Email: rvaradhan@jhmi.edu Webpage: http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html ---------------------------------------------------------------------------- -------- [[alternative HTML version deleted]]
Vincent Goulet
2008-Mar-13 17:08 UTC
[R] Use of ellipses ... in argument list of optim(), integrate(), etc.
From the NEWS file: CHANGES IN R VERSION 2.6.0 SIGNIFICANT USER-VISIBLE CHANGES o integrate(), nlm(), nlminb(), optim(), optimize() and uniroot() now have '...' much earlier in their argument list. This reduces the chances of unintentional partial matching but means that the later arguments must be named in full. --- Vincent Goulet, Associate Professor ?cole d'actuariat Universit? Laval, Qu?bec Vincent.Goulet at act.ulaval.ca http://vgoulet.act.ulaval.ca Le jeu. 13 mars ? 12:05, Ravi Varadhan a ?crit :> Hi, > > > > I have noticed that there is a change in the use of ellipses or . in R > versions 2.6.1 and later. In versions 2.5.1 and earlier, the . were > always > at the end of the argument list, but in 2.6.1 they are placed after > the main > arguments and before method control arguments. This results in the > user > having to specify the exact (complete) names of the control > arguments, i.e. > partial matching is not allowed. > > An example with integrate() : > >> integrate(function(x) exp(-x^2), lower=-Inf, upper=L, subdiv=1000) > > Error in f(x, ...) : unused argument(s) (subdiv = 1000) > >> integrate(function(x) exp(-x^2), lower=-Inf, upper=L, >> subdivisions=1000) > > 1.633051 with absolute error < 1.6e-06 > > Here is an example with optim(): > >> res <- optim(50, fw, meth="BFGS", control=list(maxit=20000, temp=20, > parscale=20)) > > Error in fn(par, ...) : unused argument(s) (meth = "BFGS") > > FYI, I am using R version 2.6.1 on Windows XP. > > May I ask what the rationale behind this change is and also about > the pros > and cons of the two different ways of specifying (.)? > > Thank you very much. > > Best, > > Ravi. > > ------------------------------------------------------------ > Ravi Varadhan, Ph.D. > Assistant Professor, The Center on Aging and Health > Division of Geriatric Medicine and Gerontology > Johns Hopkins University > Ph: (410) 502-2619 > Fax: (410) 614-9625 > Email: rvaradhan at jhmi.edu > Webpage: http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html > ----------------------------------------------------------------------------
Tony Plate
2008-Mar-13 17:19 UTC
[R] Use of ellipses ... in argument list of optim(), integrate(), etc.
Ravi Varadhan wrote:> Hi, > > I have noticed that there is a change in the use of ellipses or . in R > versions 2.6.1 and later. In versions 2.5.1 and earlier, the . were always > at the end of the argument list, but in 2.6.1 they are placed after the main > arguments and before method control arguments. This results in the user > having to specify the exact (complete) names of the control arguments, i.e. > partial matching is not allowed. > > An example with integrate() : > >> integrate(function(x) exp(-x^2), lower=-Inf, upper=L, subdiv=1000) > > Error in f(x, ...) : unused argument(s) (subdiv = 1000) > >> integrate(function(x) exp(-x^2), lower=-Inf, upper=L, subdivisions=1000) > > 1.633051 with absolute error < 1.6e-06 > > Here is an example with optim(): > >> res <- optim(50, fw, meth="BFGS", control=list(maxit=20000, temp=20, > parscale=20)) > > Error in fn(par, ...) : unused argument(s) (meth = "BFGS") > > FYI, I am using R version 2.6.1 on Windows XP. > > May I ask what the rationale behind this change is and also about the pros > and cons of the two different ways of specifying (.)?Putting optim() arguments after the ... disallows the use of abbreviated actual arguments for optim(). This is generally a good thing, because prior to this change, it was impossible to supply, via the '...' arguments of optim(), an argument to fn() whose name was a prefix of one of the arguments of optim(). E.g., if your function had a argument named 'm', you could not previously supply it via the '...' argument of optim(), because if you did something like optim(x, fun, m=240), intending 'm' to be passed to 'fun', the 'm' would instead match the 'method' argument of optim(). The cons of the new argument structure are that abbreviations for names of arguments of optim() can't be used (a minor and debatable con), and that previous code that used abbreviations might break, but it will likely break quickly and noisily, so it's not too bad (the only case where it wouldn't break is when fn has a '...' argument itself, and it ignores unrecognized components, or where the are other argument name collisions). -- Tony Plate> > > > Thank you very much. > > > > Best, > > Ravi. > > > > ---------------------------------------------------------------------------- > ------- > > Ravi Varadhan, Ph.D. > > Assistant Professor, The Center on Aging and Health > > Division of Geriatric Medicine and Gerontology > > Johns Hopkins University > > Ph: (410) 502-2619 > > Fax: (410) 614-9625 > > Email: rvaradhan at jhmi.edu > > Webpage: http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html > > > > ---------------------------------------------------------------------------- > -------- > > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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. >
Prof Brian Ripley
2008-Mar-13 18:00 UTC
[R] Use of ellipses ... in argument list of optim(), integrate(), etc.
There is an entry in the NEWS file for 2.6.0: CHANGES IN R VERSION 2.6.0 SIGNIFICANT USER-VISIBLE CHANGES o integrate(), nlm(), nlminb(), optim(), optimize() and uniroot() now have '...' much earlier in their argument list. This reduces the chances of unintentional partial matching but means that the later arguments must be named in full. and there was a spate of instances of 'unintentional partial matching' at the time. I have have no idea what you mean by 'ellipses or .' -- this is literally '...', and ellipses (e.g. Unicode U+226) do not work. From http://en.wikipedia.org/wiki/Ellipsis Most programming languages other than Perl6 require the ellipsis to be written as a series of periods; a single (Unicode) ellipsis character cannot be used. Please use R-devel for questions about the design and development of R (see the posting guide). On Thu, 13 Mar 2008, Ravi Varadhan wrote:> Hi, > > > > I have noticed that there is a change in the use of ellipses or . in R > versions 2.6.1 and later. In versions 2.5.1 and earlier, the . were always > at the end of the argument list, but in 2.6.1 they are placed after the main > arguments and before method control arguments. This results in the user > having to specify the exact (complete) names of the control arguments, i.e. > partial matching is not allowed. > > > > An example with integrate() : > > > >> integrate(function(x) exp(-x^2), lower=-Inf, upper=L, subdiv=1000) > > > > Error in f(x, ...) : unused argument(s) (subdiv = 1000) > > > >> integrate(function(x) exp(-x^2), lower=-Inf, upper=L, subdivisions=1000) > > > > 1.633051 with absolute error < 1.6e-06 > > > > > > Here is an example with optim(): > > > >> res <- optim(50, fw, meth="BFGS", control=list(maxit=20000, temp=20, > parscale=20)) > > > > Error in fn(par, ...) : unused argument(s) (meth = "BFGS") > > > > > > FYI, I am using R version 2.6.1 on Windows XP. > > > > May I ask what the rationale behind this change is and also about the pros > and cons of the two different ways of specifying (.)? > > > > Thank you very much. > > > > Best, > > Ravi. > > > > ---------------------------------------------------------------------------- > ------- > > Ravi Varadhan, Ph.D. > > Assistant Professor, The Center on Aging and Health > > Division of Geriatric Medicine and Gerontology > > Johns Hopkins University > > Ph: (410) 502-2619 > > Fax: (410) 614-9625 > > Email: rvaradhan at jhmi.edu > > Webpage: http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html > > > > ---------------------------------------------------------------------------- > -------- > > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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. >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595