The OP appears to be confused about argument lists and argument passing (which has nothing to do with "imputed variables" btw). Here is an explanation providing a more explicit explanation than RUI's post.
The formal arguments of fun1 are "x", "y",and "z". The formal arguments of fun2 are "aa" and "..." So, first of all, the call fun2(x=1, y=4, z=8) will fail at the first statement fun1(x=aa,y=5) ##lazy evaluation because aa is missing and therefore x is missing. So the OP has posted incorrectly -- all the claims made therein are false. Assuming, as RUI did, that the fun2 call was therefore really fun2(aa=1, y=4, z=8) then the call will fail as claimed by the OP. This is why: The formal argument list of fun2 has only aa and .... So, as Rui's answer implied (but did not explain fully), the call fun2(aa=1, y=4, z=8) would cause the y and z arguments to become part of the ... list. Hence the call d=fun1(x=aa, y=5, ...) has the y argument occurring twice (as y=4 and y=5), resulting in the error message seen. Given this confusion and also Rui's comment on ";", I would strongly recommend that the OP spend some time with the R Language Definition manual (presumably, he/she has already read the Intro to R manual, which always should be first, even _before_ posting). Cheers, Bert On Thu, Aug 30, 2012 at 3:58 PM, Rui Barradas <ruipbarra...@sapo.pt> wrote: > Hello, > > You could see what is fun1 receiving with this modification meant for > debugging: > > fun1 <-function(x, y, z=10){ > print(match.call()) > x + y + z > } > > Anyway, there is s standard way of dealing with argument '...' when one > needs to know what was passed. > Include dots <- list(...) at the beginning of fun2 and then use it when > necessary: > > fun1 <-function(x, y, z=10){x + y + z} > > fun2 <-function(aa, ...) { > dots <- list(...) > a <- fun1(x=aa, y=5) # works well a=1+5+10=16 > b <- fun1(x=aa, ...) # works well b=1+4+8=13 > y <- 0 # it will not affect values passed using ... > c <- fun1(x=aa, ...) # works well but c = 1+4+8=13 > d <- fun1(x=aa, y=5, dots$z) # works well d=1+5+8=14 > c(a, b, c, d) > } > > fun2(aa=1, y=4, z=8) > [1] 16 13 13 14 > > > Also, to end statements with ';' is a C language tique, R doesn't need it. > (Nor it hurts.) > > Hope this helps, > > Rui Barradas > > Em 30-08-2012 23:07, Zhiqiu Hu escreveu: >> >> Dear Friends, >> >> Let's assume there are three parameters that were passed into fun1. In >> fun1, we need to modify one para but the remains need to be untouched. And >> then all parameters were passed into fun2. However, I have failed to >> achieve it. >> >> Please see the following code. >> >> ########################################## >> fun1 <-function(x, y, z=10) {x+y+z;} >> >> fun2 <-function(aa, ...) { >> a=fun1(x=aa, y=5); # works well a=1+5+10=16 >> b=fun1(x=aa, ...); # works well b=1+4+8=13 >> y=0 # it will not affect values passed using >> ... >> c=fun1(x=aa, ...) # works well but c = 1+4+8=13 >> >> # Some time we may only want to use parts of the inputed variables >> # we only want to modify y >> d=fun1(x=aa, y=5, ...); #error : formal argument "y" matched by >> multiple >> actual arguments >> #How can I get the result d=1+5+8=14? >> >> c(a, b, c) >> } >> >> fun2(x=1, y=4, z=8) >> ########################################## >> >> I will appreciate it if you would give me any suggestions. >> >> Best wishes, >> >> Zhiqiu >> >> [[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. > > > ______________________________________________ > 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. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm [[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.