Mark Heckmann
2012-Mar-05 09:24 UTC
[R] no partial matching of argument names after dots argument - why?
I noticed that the argument names after the dots argument are not partially matched. foo <- function(one, two, ...){ one + two }> foo(o=1, t=2)[1] 3 foo <- function(one, ..., two){ one + two }> foo(o=1, t=2)Fehler in one + two : 'two' fehlt Can someone explain me the reason for this behavior? THX Mark ???????????????????????????????????? Mark Heckmann Blog: www.markheckmann.de R-Blog: http://ryouready.wordpress.com
Prof Brian Ripley
2012-Mar-05 09:41 UTC
[R] no partial matching of argument names after dots argument - why?
On 05/03/2012 09:24, Mark Heckmann wrote:> I noticed that the argument names after the dots argument are not partially matched. > > foo<- function(one, two, ...){ > one + two > } >> foo(o=1, t=2) > [1] 3 > > foo<- function(one, ..., two){ > one + two > } > >> foo(o=1, t=2) > Fehler in one + two : 'two' fehlt > > > Can someone explain me the reason for this behavior?It is documented in the 'R Language Definition', Venables & Ripley 'S Programming' and perhaps elsewhere. It is a useful feature that is not used often enough. Reason: how else could you pass an argument 't' through ... ? People do get caught by this with things like lapply(fn, X=X), so where ... is involved it is always best to name exactly all arguments. (It is more efficient and easier to read if you do it anyway, which is why R CMD check nowadays NOTEs any uses of partial matching in a package it is testing.)> THX > Mark > > ???????????????????????????????????? > Mark Heckmann > Blog: www.markheckmann.de > R-Blog: http://ryouready.wordpress.com > > ______________________________________________ > 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
Patrick Burns
2012-Mar-05 11:37 UTC
[R] no partial matching of argument names after dots argument - why?
Circle 8.1.20 of 'The R Inferno' http://www.burns-stat.com/pages/Tutor/R_inferno.pdf gives the rules for argument matching. When you see them explicitly set out there, perhaps you will see why the matching is as it is. Pat On 05/03/2012 09:24, Mark Heckmann wrote:> I noticed that the argument names after the dots argument are not partially matched. > > foo<- function(one, two, ...){ > one + two > } >> foo(o=1, t=2) > [1] 3 > > foo<- function(one, ..., two){ > one + two > } > >> foo(o=1, t=2) > Fehler in one + two : 'two' fehlt > > > Can someone explain me the reason for this behavior? > > THX > Mark > > ???????????????????????????????????? > Mark Heckmann > Blog: www.markheckmann.de > R-Blog: http://ryouready.wordpress.com > > ______________________________________________ > 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. >-- Patrick Burns pburns at pburns.seanet.com twitter: @portfolioprobe http://www.portfolioprobe.com/blog http://www.burns-stat.com (home of 'Some hints for the R beginner' and 'The R Inferno')
Maybe Matching Threads
- using regular expressions to retrieve a digit-digit-dot structure from a string
- modifying the dots argument - how?
- Reordering the results from table(cut()) by break argument
- evaluate variable within expression - how?
- "figure margins too large" in RGtk2 drawing area as cairo device - why?