Hi: Another option is to provide a default value of an argument that can be changed by the user:
add <- function(x, y = 3) x + y > add(4) [1] 7 > add(4, 2) [1] 6 There are several options at one's disposal - the trick is to figure out what you want to provide to the user of the function. HTH, Dennis On Mon, Feb 7, 2011 at 9:06 PM, David Winsemius <dwinsem...@comcast.net>wrote: > > On Feb 7, 2011, at 11:33 PM, Martin Spindler wrote: > > Dear all, >> >> I have the following problem: >> >> add <- function(x,y) {x+y} >> >> What is the easiest / most elegant way to create a new function (e.g. with >> the name "addev") that sets the second argument of the function "add" to a >> fixed value (e.g. y=3), i.e. addev <- add(x,3). But this does not work. >> > > > add <- function(x,y) {x+y} > > addev <- add > > formals(addev) <- alist(x=,y=3) > > addev(1) > [1] 4 > > > Although that might not be what you meant by "fixed" so this is another > method with a different result: > > addev <- add > > body(addev) <- quote(x+3) > > addev(4) > [1] 7 > > > > >> Thank you for your efforts in advance! >> >> Best, >> >> Martin >> -- >> >> >> >> >> -- >> Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir >> belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de >> >> ______________________________________________ >> 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. >> > > David Winsemius, MD > West Hartford, CT > > > ______________________________________________ > 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. > [[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.