[18736] in s-news-athena

home help back first fref pref prev next nref lref last post

Re: [S] Error in function...

daemon@ATHENA.MIT.EDU (Prof Brian D Ripley)
Sat Jul 24 16:25:25 1999

Date: Sat, 24 Jul 1999 21:22:05 +0100 (BST)
From: Prof Brian D Ripley <ripley@stats.ox.ac.uk>
To: Luca Boni <boni@ermes.cba.unige.it>
Cc: s-news@wubios.wustl.edu
In-Reply-To: <3.0.6.32.19990724172907.009db100@ermes.cba.unige.it>
Message-Id: <Pine.GSO.4.05.9907242118180.23836-100000@auk.stats>
Mime-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII


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

home help back first fref pref prev next nref lref last post