[R] R object as a function
Duncan Murdoch
murdoch at stats.uwo.ca
Tue Jan 22 14:35:27 CET 2008
On 1/22/2008 7:52 AM, Thomas Steiner wrote:
> Thank you very much Duncan for your quick answers.
>
>> You're not passing a function as myfunk1, you're passing mf, which is
>> the result of evaluating myfun1, so it's a numeric vector.
>
> Yes, this is exacty my problem.
> If I leave it away, the problem will not be resolved (it needs pa or not)
>
> myfun1<-function(x,pa) {
> return(pa[1]*x^2+pa[2]*x+pa[3])
> }
> myfun2<-function(x,param,myfunk1) {
> return(param[1]*myfunk1(x)+param[2]*myfunk1(x))
> }
> test<-function(pars1,pars2,lo,up){
> integ=integrate(f=myfun2,lower=lo,upper=up,param=pars2,myfunk1=myfun1)#pa=pars1
> return( 2*integ$value )
> }
> test(pars1=c(1,2,3),pars2=c(-1,1),lo=2,up=7)
>
> Which gives an error:
> Once the "argument pa" is missing and if you add the "pa=pars1" in
> the comment, it says that the argument pa is redundant.
myfun2 has no pa argument, but it calls (through myfunk1) myfun1 which
does. Where is pa supposed to come from?
You need to think carefully about the requirements for arguments to each
of your functions. Look at every function call, and make sure the
arguments you are passing match the arguments in the header of the
function you call.
Duncan Murdoch
More information about the R-help
mailing list