On Sat, 24 Jul 1999, Luca Boni wrote:
>
> I wrote this simple function:
>
> "ct.planning"<-
> function( tev, tref, mc, hratio, accrual, tmin, nc.c = 0, nc.i = 0 )
> {
> totp<-uniroot( function(x) e.ev( tref, mc, hratio, x, accrual, tmin,
> nc.c,
> nc.i ) - tev, c(1,50000))$root
> totp
> }
>
> (Note that e.ev is another function that I wrote and it works well).
> When I make a call to ct.planning, an error occurs:
> Error in f(1): Object "mc" not found
This is a scope problem: you need to understand the S scope rules, and how
to deal with them (allocate mc to frame 1). In short, mc is not visible
to any routine called by uniroot: another solution is to do something
like
> totp<-uniroot( function(x,mc) e.ev( tref, mc, hratio, x, accrual,
[...]), mc=mc)
See ?uniroot for an explanation.
In short: S does not have hierarchical scope.
--
Brian D. Ripley, ripley@stats.ox.ac.uk
Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel: +44 1865 272861 (self)
1 South Parks Road, +44 1865 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news
|