[R] no partial matching of argument names after dots argument - why?

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon Mar 5 10:41:35 CET 2012


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



More information about the R-help mailing list