Thank you very much for your help. It works very well!
Still, it is not very clear why the "replicate" function do not take the "..." arguments like they should. ----- Mensaje original ----- De: Duncan Murdoch <murdoch.dun...@gmail.com> Fecha: MiƩrcoles, 6 de Abril de 2011, 11:56 am Asunto: Re: [R] Use of the dot.dot.dot option in functions. A: KENNETH R CABRERA <krcab...@une.net.co> CC: r-help@r-project.org > On 06/04/2011 12:04 PM, KENNETH R CABRERA wrote: > >Hi R users: > > > >I try this code, where "fun" is a parameter of a random generating > >function name, and I pretend to use "..." parameter to pass the > parameters>of different random generating functions. > > > >What am I doing wrong? > > > >f1<-function(nsim=20,n=10,fun=rnorm,...){ > > vp<- > replicate(nsim,t.test(fun(n,...),fun(n,...))$p.value)> return(vp) > >} > > > >This works! > >f1() > >f1(n=20,mean=10) > > > >This two fails: > >f1(n=10,fun=rexp) > >f1(n=10,fun=rbeta,shape1=1,shape2=2) > > > >Thank you for your help. > > > I imagine it's a scoping problem: replicate() is probably not > evaluating the ... in the context you think it is. You > could debug this by writing a function like > > showArgs <- function(n, ...) { > print(n) > print(list(...)) > } > > and calling f1(n=10, fun=showArgs), but it might be easier just > to avoid the problem: > > f1 <- function(nsim=20,n=10,fun=rnorm,...){ > force(fun) > force(n) > localfun <- function() fun(n, ...) > vp<-replicate(nsim,t.test(localfun(), > localfun())$p.value) return(vp) > } > > [[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.