Hi, I know this is a simple question, but I've been having problems passing additional arguments through '...'. It is not matching the arguments correctly if the permanent argument of the function begins with the same letter as the additional argument. The following example will help show what I mean: fun.tester <- function(abc,...){ + print(abc) + } But if I input: fun.tester(0,a=1) It returns the value '1' for abc. It does however, work properly if I input: fun.tester(abc=0,a=1) It seems like a simple problem, so I would assume I'm doing something stupid, but I haven't been able to find a solution anywhere. Thanks! -- View this message in context: http://www.nabble.com/Passing-additional-arguments-through-%27...%27-tp24501159p24501159.html Sent from the R help mailing list archive at Nabble.com.
Please consult the R Language Definition for a detailed explantion, but... In brief, the evaluator first tries to match formal arguments by name, first exactly, then partially, before matching by position, so "a" partially matches formal argument "abc". e.g. contrast> fun.tester(0,b=1) ## "b" does not partially match "abc"[1] 0 Bert Gunter Genentech Nonclinical Biostatistics -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of escher2079 Sent: Wednesday, July 15, 2009 9:06 AM To: r-help at r-project.org Subject: [R] Passing additional arguments through '...' Hi, I know this is a simple question, but I've been having problems passing additional arguments through '...'. It is not matching the arguments correctly if the permanent argument of the function begins with the same letter as the additional argument. The following example will help show what I mean: fun.tester <- function(abc,...){ + print(abc) + } But if I input: fun.tester(0,a=1) It returns the value '1' for abc. It does however, work properly if I input: fun.tester(abc=0,a=1) It seems like a simple problem, so I would assume I'm doing something stupid, but I haven't been able to find a solution anywhere. Thanks! -- View this message in context: http://www.nabble.com/Passing-additional-arguments-through-%27...%27-tp24501 159p24501159.html Sent from the R help mailing list archive at Nabble.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.
On Wed, 15 Jul 2009, escher2079 wrote:> > Hi, > > I know this is a simple question, but I've been having problems passing > additional arguments through '...'. It is not matching the arguments > correctly if the permanent argument of the function begins with the same > letter as the additional argument. The following example will help show what > I mean: > > fun.tester <- function(abc,...){ > + print(abc) > + } > > But if I input: > fun.tester(0,a=1) > > It returns the value '1' for abc. It does however, work properly if I input: > fun.tester(abc=0,a=1) >I think you'll need to dig into sys.call() and match.call() and put together your own matching scheme to force a function to first match by position and then match all else by name. If match.call() is unfamiliar to you, it is advised to read the first 10 lines of lm(). HTH, Chuck p.s. every argument that comes AFTER '...' in the formals must match exactly. Perhaps this would help you.> It seems like a simple problem, so I would assume I'm doing something > stupid, but I haven't been able to find a solution anywhere. Thanks! > -- > View this message in context: http://www.nabble.com/Passing-additional-arguments-through-%27...%27-tp24501159p24501159.html > Sent from the R help mailing list archive at Nabble.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. >Charles C. Berry (858) 534-2098 Dept of Family/Preventive Medicine E mailto:cberry at tajo.ucsd.edu UC San Diego http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901