[R] Sloppy argument checking for named arguments

Wiener, Matthew matthew_wiener at merck.com
Thu Jun 3 05:20:51 CEST 2004

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.  


> f <- function(foobar = 0){print(foobar)}
> f
function(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.

 > 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.


R-help at stat.math.ethz.ch mailing list
PLEASE do read the posting guide!

More information about the R-help mailing list