[R] Sloppy argument checking for named arguments

Wolski wolski at molgen.mpg.de
Thu Jun 3 08:32:12 CEST 2004

Hi Gabor, Christian, R users!

I asked several days ago how to provide a signature in S4 for an existing function of the type which gabor proposes.
There are already some functions in the base package which are using the syntax sugested by you.


rbind <-
function (..., deparse.level = 1) 

But I have not found any way to provide a signature (to overload) such functions in S4.


simple does not work.

Therefore, when I am programming new functions, I am try to think about, how to do not clutter the name space. It means how to choose argument names, so that other people can use the same functions names programming they own classes. That means that the parameter names, especially the name of the first parameters should be as 
general as possible e.g 'x' (as for most graphic functions in the base package)
or 'object' as eg. for the summary function in base package.

This also means to me not to use argument names with '.' like foo.bar!

S3 does argument checking  so if you provide a function f(...) it means that all other packages that like to work with you package and want to implement a function f for they own classes have to provide to it the same arguments (e.g. f.myclass<-funtion(...)) .  But even worser with S4 ... see above.

Would be nice if someone proofs that I am false. 



*********** REPLY SEPARATOR  ***********

On 6/3/2004 at 4:15 AM Gabor Grothendieck wrote:

>>>It has already been pointed out that partial matching is a feature.
>>>However, if the function uses ... then it will only match arguments 
>>>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!
>>>R-help at stat.math.ethz.ch mailing list
>>>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Dipl. bio-chem. Eryk Witold Wolski    @    MPI-Moleculare Genetic   
Ihnestrasse 63-73 14195 Berlin       'v'    
tel: 0049-30-83875219               /   \    
mail: wolski at molgen.mpg.de        ---W-W----    http://www.molgen.mpg.de/~wolski

More information about the R-help mailing list