Christian -- This is not a bug, but a feature, and the dot is not the issue here. R uses partial argument matching on function arguments. So:> f <- function(foobar = 0){print(foobar)} > ffunction(foobar = 0){print(foobar)}> > f(fo=1)[1] 1> f(foo=1)[1] 1> f(foob=1)[1] 1> f(fooba=1)[1] 1> f(foon=1)Error in f(foon = 1) : unused argument(s) (foon ...)> > f(foobar2=1)Error in f(foobar2 = 1) : unused argument(s) (foobar2 ...) This is mentioned in Venables & Ripley, MASS 4th edition on p. 55. I can't find it right now in the "Introduction to R" that is linked to on the main html help index page. However, it is discussed in the R Language Definition you can get to from the same page. It seems like there must be an easier path to the information that I haven't thought of. Hope this helps, Matt Wiener -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of christianlederer at t-online.de Sent: Thursday, June 03, 2004 12:20 AM To: r-help at stat.math.ethz.ch Subject: [R] Sloppy argument checking for named arguments 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
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! http://www.R-project.org/posting-guide.html
:
:
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
> 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 argumentsI 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 > >