Michael Hannon
2011-Jul-25 22:00 UTC
[R] Simple example of using a closure in R to manage bank accounts?
Greetings. I once ran across a simple (toy) example of using a closure in R to manage bank accounts. I've got a use for it now but can no longer find it. If you have it (or a similar example), will you please send it to me? (Unfortunately, a web search that includes the terms "bank" and "closure" leads into a whole pile of unrelated stuff.) Thanks, -- Mike
Leo Guelman
2011-Jul-25 22:16 UTC
[R] Simple example of using a closure in R to manage bank accounts?
something like this maybe? account <- function (balance=0) { function (d = 0,w = 0) { newbal <- balance + d - w balance <<- newbal newbal } } John <- account(100) John John(d=100,w=50) John() Leo <- account(1000) Leo Leo(d=1000,w=50) Leo() Leo(d=100,w=500) Leo() Leo. On Mon, Jul 25, 2011 at 6:00 PM, Michael Hannon <jm_hannon@yahoo.com> wrote:> Greetings. I once ran across a simple (toy) example of using a closure in > R to > manage bank accounts. I've got a use for it now but can no longer find it. > If > you have it (or a similar example), will you please send it to me? > (Unfortunately, a web search that includes the terms "bank" and "closure" > leads > into a whole pile of unrelated stuff.) > > Thanks, > > -- Mike > > ______________________________________________ > 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. >[[alternative HTML version deleted]]
Gabor Grothendieck
2011-Jul-25 22:40 UTC
[R] Simple example of using a closure in R to manage bank accounts?
On Mon, Jul 25, 2011 at 6:00 PM, Michael Hannon <jm_hannon at yahoo.com> wrote:> Greetings. ?I once ran across a simple (toy) example of using a closure in R to > manage bank accounts. ?I've got a use for it now but can no longer find it. ?If > you have it (or a similar example), will you please send it to me? > (Unfortunately, a web search that includes the terms "bank" and "closure" leads > into a whole pile of unrelated stuff.) >demo("scoping") -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com