[R] Sloppy argument checking for named arguments

Liaw, Andy andy_liaw at merck.com
Fri Jun 4 21:59:03 CEST 2004


> From: Gabor Grothendieck
> 
> It has already been pointed out that partial matching is a feature.
> 
> However, if the function uses ... then it will only match arguments 

I believe a more precise description is: `no partial (or positional)
matching for arguments that come after the ...'.

Best,
Andy


> exactly so if you want to write a function in which full 
> matching only 
> is accepted you can do it by putting in a dummy first argument of 
> ... and then issuing an error messaage if ... matches anything:
> 
> f <- function( ..., foo.bar = 0 )  { 
>           stopifnot( length(list(...)) == 0 )
>           print( foo.bar )
> }
> 
>  
> R> f( foo.bar = 1 )
> [1] 1
> R> f( foo = 1 )
> Error: length(list(...)) == 0 is not TRUE
> 
> 
> Christian Lederer <christianlederer <at> t-online.de> writes:
> 
> : 
> : Dear R Gurus,
> : 
> : i recently noticed that R does sloppy argument checking for named
> : arguments, if the argument contains a dot.
> : Example:
> : 
> :  > f <- function(foo.bar=0) { print(foo.bar) }
> :  > f(foo=1)
> : [1] 1
> : 
> : I guess, this should be considered as a bug.
> : Anyway, the consequence is that bugs caused by typing errors
> : of this kind may are *very* hard to discover in complex progams.
> : 
> : Christian
> : 
> : ______________________________________________
> : R-help <at> stat.math.ethz.ch mailing list
> : https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> : PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html
> : 
> :
> 
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html
> 
>




More information about the R-help mailing list