I think you'll have to code it a bit different. I'd do : f <- function(x,y){ if(missing(y)) y <-x x+y } > f(2) [1] 4 > f(2,3) [1] 5 >
On Tue, May 4, 2010 at 4:26 PM, Thorn <thorn.tha...@rdls.nestle.com> wrote: > Hi everybody, > > how is it possible to refer to an argument passed to a function in the > function call? What I like to do, is something like > > f <- function(x,y) x+y > f(2, x) # should give 4 > > The problem is of course that x is only known inside the function. Of > course I > could specify something like > > f(z<-2,z) > > but I'm just curious whether it is possible to use a fancy combination of > eval, substitute or quote ;) > > BR, thorn > > ______________________________________________ > R-help@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. > -- Joris Meys Statistical Consultant Ghent University Faculty of Bioscience Engineering Department of Applied mathematics, biometrics and process control Coupure Links 653 B-9000 Gent tel : +32 9 264 59 87 joris.m...@ugent.be ------------------------------- Disclaimer : http://helpdesk.ugent.be/e-maildisclaimer.php [[alternative HTML version deleted]] ______________________________________________ R-help@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.